/
impl.go
74 lines (59 loc) · 1.33 KB
/
impl.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
65
66
67
68
69
70
71
72
73
74
package impl
import (
"context"
"github.com/infraboard/mcube/app"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
"google.golang.org/grpc"
"github.com/infraboard/keyauth/apps/tag"
"github.com/infraboard/keyauth/conf"
)
var (
// Service 服务实例
svr = &service{}
)
type service struct {
key *mongo.Collection
value *mongo.Collection
enableCache bool
log logger.Logger
tag.UnimplementedServiceServer
}
func (s *service) Config() error {
db := conf.C().Mongo.GetDB()
key := db.Collection("tag_key")
indexs := []mongo.IndexModel{
{
Keys: bsonx.Doc{{Key: "create_at", Value: bsonx.Int32(-1)}},
},
}
_, err := key.Indexes().CreateMany(context.Background(), indexs)
if err != nil {
return err
}
value := db.Collection("tag_value")
vIndexs := []mongo.IndexModel{
{
Keys: bsonx.Doc{{Key: "create_at", Value: bsonx.Int32(-1)}},
},
}
_, err = value.Indexes().CreateMany(context.Background(), vIndexs)
if err != nil {
return err
}
s.key = key
s.value = value
s.log = zap.L().Named("Tag")
return nil
}
func (s *service) Name() string {
return tag.AppName
}
func (s *service) Registry(server *grpc.Server) {
tag.RegisterServiceServer(server, svr)
}
func init() {
app.RegistryGrpcApp(svr)
}