/
basic.go
64 lines (53 loc) · 1.26 KB
/
basic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package service
import (
"context"
"fmt"
"github.com/ijidan/jsocial/api/proto_build"
"github.com/opentracing/opentracing-go"
)
// BasicService 基本服务类
type BasicService struct {
Name string
Host string
Port uint
Ttl int64
}
// GetName 获取服务名称
func (s *BasicService) GetName() string {
return s.Name
}
func (s *BasicService) GetAddress() string {
address := fmt.Sprintf("%s:%d",s.Host, s.Port)
return address
}
func (s *BasicService) GetTTL() int64 {
return s.Ttl
}
func (s *BasicService)AddSpan(c context.Context,funcName string,req interface{},rsp interface{}) {
span, _ := opentracing.StartSpanFromContext(c, s.Name)
defer func() {
span.SetTag("func",funcName)
span.SetTag("request", req)
span.SetTag("reply", rsp)
span.Finish()
}()
}
func (s *BasicService) SuccessCommon() *proto_build.CommonResponse {
rsp:=&proto_build.CommonResponse{
ErrorCode: 0,
BusinessCode: 0,
Message: "success",
}
return rsp
}
func (s *BasicService) FailCommon(errorCode uint64,businessCode uint64,message string) *proto_build.CommonResponse {
rsp:=&proto_build.CommonResponse{
ErrorCode: errorCode ,
BusinessCode: businessCode,
Message: message,
}
return rsp
}
func (s *BasicService) GetLoginUserId() uint64 {
return 9
}