usermngmt/cache/db.go

78 lines
1.8 KiB
Go
Raw Permalink Normal View History

2021-11-11 08:16:17 +00:00
package cache
import (
"context"
2022-10-10 03:46:33 +00:00
"git.selly.red/Selly-Modules/logger"
"git.selly.red/Selly-Modules/usermngmt/database"
"git.selly.red/Selly-Modules/usermngmt/model"
2021-11-11 08:16:17 +00:00
"go.mongodb.org/mongo-driver/mongo/options"
)
func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBRole) {
var (
col = database.GetRoleCol()
)
docs = make([]model.DBRole, 0)
cursor, err := col.Find(ctx, cond, opts...)
if err != nil {
logger.Error("usermngmt - Role - Find", logger.LogData{
2022-10-05 10:59:08 +00:00
Source: "usermngmt.roleFindByCondition",
Message: err.Error(),
Data: map[string]interface{}{
"cond": cond,
"opts": opts,
},
2021-11-11 08:16:17 +00:00
})
2022-10-05 10:59:08 +00:00
2021-11-11 08:16:17 +00:00
return
}
defer cursor.Close(ctx)
if err = cursor.All(ctx, &docs); err != nil {
logger.Error("usermngmt - Role - Decode", logger.LogData{
2022-10-05 10:59:08 +00:00
Source: "usermngmt.roleFindByCondition",
Message: err.Error(),
Data: map[string]interface{}{
"cond": cond,
"opts": opts,
},
2021-11-11 08:16:17 +00:00
})
return
}
return
}
func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) {
var (
col = database.GetPermissionCol()
)
docs = make([]model.DBPermission, 0)
cursor, err := col.Find(ctx, cond, opts...)
if err != nil {
logger.Error("usermngmt - Permission - Find", logger.LogData{
2022-10-05 10:59:08 +00:00
Source: "usermngmt.permissionFindByCondition",
Message: err.Error(),
Data: map[string]interface{}{
"cond": cond,
"opts": opts,
},
2021-11-11 08:16:17 +00:00
})
return
}
defer cursor.Close(ctx)
if err = cursor.All(ctx, &docs); err != nil {
logger.Error("usermngmt - Permission - Decode", logger.LogData{
2022-10-05 10:59:08 +00:00
Source: "usermngmt.permissionFindByCondition",
Message: err.Error(),
Data: map[string]interface{}{
"cond": cond,
"opts": opts,
},
2021-11-11 08:16:17 +00:00
})
return
}
return
}