first commit
This commit is contained in:
48
gateway/api/v1/internal/svc/servicecontext.go
Normal file
48
gateway/api/v1/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/interceptor/trace"
|
||||
group "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
store "gitlab.33.cn/chat/dtalk/service/record/store/api"
|
||||
"google.golang.org/grpc"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/config"
|
||||
answer "gitlab.33.cn/chat/dtalk/service/record/answer/api"
|
||||
)
|
||||
|
||||
// ServiceContext 服务上下文
|
||||
type ServiceContext struct {
|
||||
m sync.RWMutex
|
||||
c config.Config
|
||||
|
||||
AnswerClient *answer.Client
|
||||
StoreClient *store.Client
|
||||
GroupClient *group.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
sc := &ServiceContext{
|
||||
c: c,
|
||||
AnswerClient: answer.New(c.AnswerRPCClient.RegAddrs, c.AnswerRPCClient.Schema, c.AnswerRPCClient.SrvName, time.Duration(c.AnswerRPCClient.Dial)),
|
||||
StoreClient: store.New(c.StoreRPCClient.RegAddrs, c.StoreRPCClient.Schema, c.StoreRPCClient.SrvName, time.Duration(c.StoreRPCClient.Dial)),
|
||||
GroupClient: group.New(c.GroupRPCClient.RegAddrs,
|
||||
c.GroupRPCClient.Schema,
|
||||
c.GroupRPCClient.SrvName,
|
||||
time.Duration(c.GroupRPCClient.Dial),
|
||||
grpc.WithChainUnaryInterceptor(xerror.ErrClientInterceptor, trace.UnaryClientInterceptor),
|
||||
),
|
||||
}
|
||||
|
||||
return sc
|
||||
}
|
||||
|
||||
// Config 获取全局配置
|
||||
func (sc *ServiceContext) Config() config.Config {
|
||||
sc.m.RLock()
|
||||
defer sc.m.RUnlock()
|
||||
|
||||
return sc.c
|
||||
}
|
||||
Reference in New Issue
Block a user