22 lines
553 B
Go
22 lines
553 B
Go
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) []*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`"))
|
|
if err == nil {
|
|
return result.([]*types.TypeValue)
|
|
}
|
|
return nil
|
|
}
|