-
Notifications
You must be signed in to change notification settings - Fork 28
/
impl.go
54 lines (42 loc) · 935 Bytes
/
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
package impl
import (
"context"
"github.com/infraboard/keyauth/apps/wxwork"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/bsonx"
"github.com/infraboard/keyauth/conf"
"github.com/infraboard/mcube/app"
)
var (
// Service 服务实例
svr = &service{}
)
type service struct {
col *mongo.Collection
}
func (s *service) Config() error {
db := conf.C().Mongo.GetDB()
ac := db.Collection("wxwork")
indexs := []mongo.IndexModel{
{
Keys: bsonx.Doc{{Key: "corp_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 wxwork.AppName
}
func init() {
app.RegistryInternalApp(svr)
}