-
Notifications
You must be signed in to change notification settings - Fork 368
/
service_context.go
53 lines (46 loc) · 1.85 KB
/
service_context.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
/*
* Created from 'scheme.tl' by 'mtprotoc'
*
* Copyright (c) 2021-present, Teamgram Studio (https://teamgram.io).
* All rights reserved.
*
* Author: teamgramio (teamgram.io@gmail.com)
*/
package svc
import (
kafka "github.com/teamgram/marmota/pkg/mq"
"github.com/teamgram/marmota/pkg/net/rpcx"
"github.com/teamgram/marmota/pkg/stores/sqlx"
"github.com/teamgram/teamgram-server/app/messenger/msg/inbox/internal/config"
"github.com/teamgram/teamgram-server/app/messenger/msg/internal/dao"
sync_client "github.com/teamgram/teamgram-server/app/messenger/sync/client"
// channel_client "github.com/teamgram/teamgram-server/app/service/biz/channel/client"
chat_client "github.com/teamgram/teamgram-server/app/service/biz/chat/client"
dialog_client "github.com/teamgram/teamgram-server/app/service/biz/dialog/client"
user_client "github.com/teamgram/teamgram-server/app/service/biz/user/client"
idgen_client "github.com/teamgram/teamgram-server/app/service/idgen/client"
"github.com/zeromicro/go-zero/core/stores/kv"
)
type ServiceContext struct {
Config config.Config
*dao.Dao
}
func NewServiceContext(c config.Config) *ServiceContext {
db := sqlx.NewMySQL(&c.Mysql)
dao := &dao.Dao{
Mysql: dao.NewMysqlDao(db),
KV: kv.NewStore(c.KV),
IDGenClient2: idgen_client.NewIDGenClient2(rpcx.GetCachedRpcClient(c.IdgenClient)),
UserClient: user_client.NewUserClient(rpcx.GetCachedRpcClient(c.UserClient)),
ChatClient: chat_client.NewChatClient(rpcx.GetCachedRpcClient(c.ChatClient)),
SyncClient: sync_client.NewSyncMqClient(kafka.GetCachedMQClient(c.SyncClient)),
DialogClient: dialog_client.NewDialogClient(rpcx.GetCachedRpcClient(c.DialogClient)),
}
if c.BotSyncClient != nil {
dao.BotSyncClient = sync_client.NewSyncMqClient(kafka.GetCachedMQClient(c.BotSyncClient))
}
return &ServiceContext{
Config: c,
Dao: dao,
}
}