22 lines
631 B
Go
22 lines
631 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, 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
|
||
|
}
|