来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
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))
|
|
}
|
|
}
|