usermngmt/cache/db.go

45 lines
925 B
Go

package cache
import (
"context"
"go.mongodb.org/mongo-driver/mongo/options"
"git.selly.red/Selly-Modules/usermngmt/database"
"git.selly.red/Selly-Modules/usermngmt/model"
)
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 {
return
}
defer cursor.Close(ctx)
if err = cursor.All(ctx, &docs); err != nil {
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 {
return
}
defer cursor.Close(ctx)
if err = cursor.All(ctx, &docs); err != nil {
return
}
return
}