init.go
732 Bytes
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
package models
import (
"pro2d/components/db"
"pro2d/protos/pb"
"pro2d/utils"
)
func InitDoc(schema ...interface{}) {
for _, s := range schema {
coll, keys := utils.FindIndex(s)
for _, index := range keys {
db.CreateCollection(coll)
utils.Sugar.Debugf("InitDoc collect: %v, createIndex: %s", coll, index)
res, err := db.SetUnique(coll, index)
if err != nil {
utils.Sugar.Errorf("InitDoc unique: %s, err: %v", res, err)
continue
}
}
}
}
func InitAccountServerModels() {
var schema []interface{} = []interface{}{
pb.Account{},
}
InitDoc(schema...)
}
func InitGameServerModels() {
var schema []interface{} = []interface{}{
pb.Hero{},
pb.Role{},
pb.Team{},
}
InitDoc(schema...)
}