init.go 732 Bytes
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...)
}