Documentation
¶
Index ¶
- func CreateFile(ctx context.Context, value *File) error
- func CreatePermission(ctx context.Context, value *Permission) error
- func CreateRole(ctx context.Context, value *Role) error
- func CreateUser(ctx context.Context, value *User) error
- func DeleteFile(ctx context.Context, value *File) error
- func DeletePermission(ctx context.Context, value *Permission) error
- func DeleteRole(ctx context.Context, value *Role) error
- func EnsureRolePermissions(tx *dbx.DB, role Role, permissions []Permission) error
- func EnsureUserRole(tx *dbx.DB, userId, roleId string) error
- func HasPermission(ctx context.Context, userId, permission string) (bool, error)
- func SetRolePermissions(ctx context.Context, id string, permissionIds []string) (bool, error)
- func SetUserRoles(ctx context.Context, id string, roleIds []string) (bool, error)
- func UpdatePermission(ctx context.Context, id string, updates map[string]any) error
- func UpdateRole(ctx context.Context, id string, updates map[string]any) error
- func UpdateUser(ctx context.Context, id string, updates map[string]any) error
- type File
- type Permission
- func EnsurePermission(tx *dbx.DB, item Permission) (Permission, error)
- func FindPermissions(ctx context.Context, ids []string) ([]Permission, error)
- func GetPermission(ctx context.Context, id string) (Permission, error)
- func ListPermissions(ctx context.Context, offset, limit int) ([]Permission, int64, error)
- type Role
- type RolePermission
- type User
- type UserRole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreatePermission ¶
func CreatePermission(ctx context.Context, value *Permission) error
func DeletePermission ¶
func DeletePermission(ctx context.Context, value *Permission) error
func EnsureRolePermissions ¶
func EnsureRolePermissions(tx *dbx.DB, role Role, permissions []Permission) error
func HasPermission ¶
func SetRolePermissions ¶
func SetUserRoles ¶
func UpdatePermission ¶
Types ¶
type File ¶
type Permission ¶
type Permission struct {
dbx.Metadata
Code string `gorm:"type:varchar(128);not null;uniqueIndex"`
Name string `gorm:"type:varchar(128);not null"`
}
func EnsurePermission ¶
func EnsurePermission(tx *dbx.DB, item Permission) (Permission, error)
EnsurePermission 按编码复用或创建权限,已存在时保留原有记录。
func FindPermissions ¶
func FindPermissions(ctx context.Context, ids []string) ([]Permission, error)
func GetPermission ¶
func GetPermission(ctx context.Context, id string) (Permission, error)
func ListPermissions ¶
type Role ¶
type Role struct {
dbx.Metadata
Code string `gorm:"type:varchar(64);not null;uniqueIndex"`
Name string `gorm:"type:varchar(128);not null"`
Permissions []Permission `gorm:"many2many:role_permissions"`
}
func EnsureRole ¶
EnsureRole 按编码复用或创建角色,已存在时保留原有记录。
type RolePermission ¶
type User ¶
type User struct {
dbx.Metadata
Username string `gorm:"type:varchar(64);not null;uniqueIndex"`
Email string `gorm:"type:varchar(255);not null;uniqueIndex"`
PasswordHash string `gorm:"type:varchar(255);not null"`
Enabled bool `gorm:"not null"`
AvatarFileId *string `gorm:"type:varchar(32);index"`
Roles []Role `gorm:"many2many:user_roles"`
}
func EnsureUser ¶
EnsureUser 按用户名复用用户,仅在记录不存在时调用 create 构造新用户。
Click to show internal directories.
Click to hide internal directories.