/
impl.go
64 lines (52 loc) · 1.23 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
package impl
import (
"context"
"github.com/infraboard/mcube/app"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/bsonx"
"google.golang.org/grpc"
"github.com/infraboard/keyauth/apps/application"
"github.com/infraboard/keyauth/conf"
)
var (
// Service 服务实例
svr = &userimpl{service: &service{}}
)
type service struct {
col *mongo.Collection
}
func (s *service) Config() error {
db := conf.C().Mongo.GetDB()
ac := db.Collection("application")
indexs := []mongo.IndexModel{
{
Keys: bsonx.Doc{
{Key: "user_id", Value: bsonx.Int32(-1)},
{Key: "name", Value: bsonx.Int32(-1)}},
Options: options.Index().SetUnique(true),
},
{
Keys: bsonx.Doc{{Key: "client_id", Value: bsonx.Int32(-1)}},
Options: options.Index().SetUnique(true),
},
{
Keys: bsonx.Doc{{Key: "create_at", Value: bsonx.Int32(-1)}},
},
}
_, err := ac.Indexes().CreateMany(context.Background(), indexs)
if err != nil {
return err
}
s.col = ac
return nil
}
func (s *service) Name() string {
return application.AppName
}
func (s *service) Registry(server *grpc.Server) {
application.RegisterServiceServer(server, svr)
}
func init() {
app.RegistryGrpcApp(svr)
}