moto/internal/organize/role.go

22 lines
631 B
Go
Raw Normal View History

2024-12-12 17:39:04 +08:00
package organize
import (
"context"
"fmt"
"git.nobla.cn/golang/moto/common/db"
"git.nobla.cn/golang/moto/models"
"git.nobla.cn/golang/rest"
"git.nobla.cn/golang/rest/types"
"gorm.io/gorm"
)
func RoleTypes(ctx context.Context, domainName string) []*types.TypeValue {
result, err := db.TryCache(ctx, fmt.Sprintf("domain:%s:role:types", domainName), func(tx *gorm.DB) (any, error) {
return rest.ModelTypes(ctx, tx, &models.Role{}, domainName, "name", "id"), nil
}, db.WithDepend("SELECT max(`updated_at`) FROM `roles` WHERE `domain`=?", domainName))
if err == nil {
return result.([]*types.TypeValue)
}
return nil
}