package mwacc import ( "context" "fmt" "hkdj-web-server/pub/mongos" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" ) // Init 初始化数据 func Init(ctx context.Context) { mwAccColl = mongos.Shop.Coll(TN.MwAcc) mwRoleColl = mongos.Shop.Coll(TN.MwRole) mwAccTokenColl = mongos.Shop.Coll(TN.MwAccToken) initIndex(ctx) return } // initIndex 初始化索引 func initIndex(ctx context.Context) { initAccIndex(ctx) initRoleIndex(ctx) initAccTokenIndex(ctx) } func initAccIndex(ctx context.Context) { indexes := []mongo.IndexModel{ { Keys: bson.D{ {FN.MwAcc.Id, 1}, }, }, } if _, err := mwAccColl.CreateIndex(ctx, indexes); err != nil { panic(fmt.Sprintf("(mwacc:initAccIndex) Create mwacc Index failed! err:%+v:", err)) } } func initRoleIndex(ctx context.Context) { indexes := []mongo.IndexModel{ { Keys: bson.D{ {FN.MwRole.Id, 1}, }, // Options: options.Index().SetUnique(true), }, } if _, err := mwRoleColl.CreateIndex(ctx, indexes); err != nil { panic(fmt.Sprintf("(mwacc:initRoleIndex) Create mwacc Index failed! err:%+v:", err)) } } func initAccTokenIndex(ctx context.Context) { indexes := []mongo.IndexModel{ { Keys: bson.D{ {FN.MwAccToken.Id, 1}, }, // Options: options.Index().SetUnique(true), }, } if _, err := mwAccTokenColl.CreateIndex(ctx, indexes); err != nil { panic(fmt.Sprintf("(mwacc:initAccTokenIndex) Create mwacc Index failed! err:%+v:", err)) } }