moto/internal/organize/role.go

22 lines
553 B
Go
Raw Permalink 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"
)
2024-12-13 10:37:09 +08:00
func RoleTypes(ctx context.Context) []*types.TypeValue {
result, err := db.TryCache(ctx, fmt.Sprintf("role:types"), func(tx *gorm.DB) (any, error) {
return rest.ModelTypes(ctx, tx, &models.Role{}, "", "name", "id"), nil
}, db.WithDepend("SELECT max(`updated_at`) FROM `roles`"))
2024-12-12 17:39:04 +08:00
if err == nil {
return result.([]*types.TypeValue)
}
return nil
}