Documentation ¶
Index ¶
- Constants
- type AddApiPermissionRequest
- type AddViewPermissionRequest
- type ApiPermission
- type ApiPermissionService
- type ApiPermissionSpec
- type CreateRoleRequest
- type DeleteRoleRequest
- type DescribeRoleRequest
- type MATCH_BY
- type QueryApiPermissionRequest
- type QueryMatchedEndpointRequest
- type QueryMatchedMenuRequest
- type QueryRoleRequest
- type QueryViewPermissionRequest
- type RemoveApiPermissionRequest
- type RemoveViewPermissionRequest
- type Role
- type RoleService
- type Service
- type UpdateApiPermissionRequest
- type UpdateRoleRequest
- type UpdateViewPermission
- type ViewPermission
- type ViewPermissionService
- type ViewPermissionSpec
Constants ¶
View Source
const ( MATCH_BY_ID = iota MATCH_BY_LABLE MATCH_BY_RESOURCE_ACTION MATCH_BY_RESOURCE_ACCESS_MODE )
View Source
const (
ADMIN = "admin"
)
View Source
const (
AppName = "role"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddApiPermissionRequest ¶
type AddApiPermissionRequest struct { RoleId uint64 `json:"role_id"` Items []*ApiPermissionSpec `json:"items"` }
func NewAddApiPermissionRequest ¶
func NewAddApiPermissionRequest() *AddApiPermissionRequest
func (*AddApiPermissionRequest) Validate ¶
func (r *AddApiPermissionRequest) Validate() error
type AddViewPermissionRequest ¶
type AddViewPermissionRequest struct { RoleId uint64 `json:"role_id"` Items []*ViewPermissionSpec `json:"items"` }
func NewAddViewPermissionRequest ¶
func NewAddViewPermissionRequest() *AddViewPermissionRequest
func (*AddViewPermissionRequest) Validate ¶
func (r *AddViewPermissionRequest) Validate() error
type ApiPermission ¶
type ApiPermission struct { // 基础数据 apps.ResourceMeta // 角色Id RoleId uint64 `json:"role_id" gorm:"column:role_id;index" description:"角色Id"` // Api权限定义 ApiPermissionSpec }
func NewApiPermission ¶
func NewApiPermission(roleId uint64, spec *ApiPermissionSpec) *ApiPermission
func (*ApiPermission) TableName ¶
func (r *ApiPermission) TableName() string
type ApiPermissionService ¶
type ApiPermissionService interface { // 查询角色关联的权限条目 QueryApiPermission(context.Context, *QueryApiPermissionRequest) ([]*ApiPermission, error) // 添加角色关联API AddApiPermission(context.Context, *AddApiPermissionRequest) ([]*ApiPermission, error) // 移除角色关联API RemoveApiPermission(context.Context, *RemoveApiPermissionRequest) ([]*ApiPermission, error) // 查询匹配到的Api接口列表 QueryMatchedEndpoint(context.Context, *QueryMatchedEndpointRequest) (*types.Set[*endpoint.Endpoint], error) }
角色API接口管理
type ApiPermissionSpec ¶
type ApiPermissionSpec struct { // 创建者ID CreateBy uint64 `json:"create_by" gorm:"column:create_by" description:"创建者ID" optional:"true"` // 角色描述 Description string `json:"description" gorm:"column:description;type:text" bson:"description" description:"角色描述"` // 权限匹配方式 MatchBy MATCH_BY `json:"match_by" gorm:"column:match_by;type:tinyint(1);index" bson:"match_by" description:"权限匹配方式"` // MATCH_BY_ID 时指定的 Endpoint Id EndpointId *uint64 `json:"endpoint_id" gorm:"column:endpoint_id;type:uint;index"` // 操作标签 Label string `json:"label" gorm:"column:label;type:varchar(200);index"` // 服务 Service string `json:"service" gorm:"column:service;type:varchar(100);index" bson:"service" description:"服务名称"` // 资源列表 Resource string `json:"resource" gorm:"column:resource;type:varchar(100);index" bson:"resource" description:"资源名称"` // 资源操作 Action string `json:"action" bson:"action" gorm:"column:action;type:varchar(100);index"` // 读或者读写 AccessMode endpoint.ACCESS_MODE `json:"access_mode" bson:"access_mode" gorm:"column:access_mode;type:tinyint(1);index"` // 其他扩展信息 Extras map[string]string `json:"extras" gorm:"column:extras;serializer:json;type:json" description:"其他扩展信息" optional:"true"` }
type CreateRoleRequest ¶
type CreateRoleRequest struct { // 创建者ID CreateBy uint64 `json:"create_by" gorm:"column:create_by" description:"创建者ID" optional:"true"` // 角色名称 Name string `json:"name" gorm:"column:name;type:varchar(100);index" bson:"name" description:"角色名称"` // 角色描述 Description string `json:"description" gorm:"column:description;type:text" bson:"description" description:"角色描述"` // 是否启用 Enabled bool `json:"enabled" bson:"enabled" gorm:"column:enabled;type:tinyint(1)" description:"是否启用" optional:"true"` // 标签 Label string `json:"label" gorm:"column:label;type:varchar(200);index" description:"标签" optional:"true"` // 其他扩展信息 Extras map[string]string `json:"extras" gorm:"column:extras;serializer:json;type:json" description:"其他扩展信息" optional:"true"` }
func NewCreateRoleRequest ¶
func NewCreateRoleRequest() *CreateRoleRequest
func (*CreateRoleRequest) Validate ¶
func (r *CreateRoleRequest) Validate() error
type DeleteRoleRequest ¶
type DeleteRoleRequest struct {
apps.GetRequest
}
func NewDeleteRoleRequest ¶
func NewDeleteRoleRequest() *DeleteRoleRequest
type DescribeRoleRequest ¶
type DescribeRoleRequest struct {
apps.GetRequest
}
func NewDescribeRoleRequest ¶
func NewDescribeRoleRequest() *DescribeRoleRequest
type QueryApiPermissionRequest ¶
type QueryApiPermissionRequest struct { RoleIds []uint64 `json:"role_ids"` ApiPermissionIds []uint64 `json:"api_permission_ids"` }
func NewQueryApiPermissionRequest ¶
func NewQueryApiPermissionRequest() *QueryApiPermissionRequest
func (*QueryApiPermissionRequest) AddPermissionId ¶
func (r *QueryApiPermissionRequest) AddPermissionId(permissionIds ...uint64) *QueryApiPermissionRequest
func (*QueryApiPermissionRequest) AddRoleId ¶
func (r *QueryApiPermissionRequest) AddRoleId(roleIds ...uint64) *QueryApiPermissionRequest
type QueryMatchedEndpointRequest ¶
type QueryMatchedEndpointRequest struct {
apps.GetRequest
}
func NewQueryMatchedEndpointRequest ¶
func NewQueryMatchedEndpointRequest() *QueryMatchedEndpointRequest
type QueryMatchedMenuRequest ¶
type QueryMatchedMenuRequest struct {
apps.GetRequest
}
func NewQueryMatchedMenuRequest ¶
func NewQueryMatchedMenuRequest() *QueryMatchedMenuRequest
type QueryRoleRequest ¶
type QueryRoleRequest struct { *request.PageRequest WithMenuPermission bool `json:"with_menu_permission"` WithApiPermission bool `json:"with_api_permission"` }
func NewQueryRoleRequest ¶
func NewQueryRoleRequest() *QueryRoleRequest
type QueryViewPermissionRequest ¶
type QueryViewPermissionRequest struct { RoleIds []uint64 `json:"role_ids"` ViewPermissionIds []uint64 `json:"view_permission_ids"` }
func NewQueryViewPermissionRequest ¶
func NewQueryViewPermissionRequest() *QueryViewPermissionRequest
func (*QueryViewPermissionRequest) AddPermissionId ¶
func (r *QueryViewPermissionRequest) AddPermissionId(permissionIds ...uint64) *QueryViewPermissionRequest
func (*QueryViewPermissionRequest) AddRoleId ¶
func (r *QueryViewPermissionRequest) AddRoleId(roleIds ...uint64) *QueryViewPermissionRequest
type RemoveApiPermissionRequest ¶
type RemoveApiPermissionRequest struct { RoleId uint64 `json:"role_id"` ApiPermissionIds []uint64 `json:"api_permission_ids"` }
func NewRemoveApiPermissionRequest ¶
func NewRemoveApiPermissionRequest() *RemoveApiPermissionRequest
func (*RemoveApiPermissionRequest) Validate ¶
func (r *RemoveApiPermissionRequest) Validate() error
type RemoveViewPermissionRequest ¶
type RemoveViewPermissionRequest struct { RoleId uint64 `json:"role_id"` ViewPermissionIds []uint64 `json:"menu_permission_ids"` }
func NewRemoveViewPermissionRequest ¶
func NewRemoveViewPermissionRequest() *RemoveViewPermissionRequest
func (*RemoveViewPermissionRequest) Validate ¶
func (r *RemoveViewPermissionRequest) Validate() error
type Role ¶
type Role struct { // 基础数据 apps.ResourceMeta // 角色创建信息 CreateRoleRequest // 菜单权限 MenuPermissions []*ViewPermission `json:"menu_permissions,omitempty" gorm:"-" description:"角色关联的菜单权限"` // API权限 ApiPermissions []*ApiPermission `json:"api_permissions,omitempty" gorm:"-" description:"角色关联的API权限"` }
type RoleService ¶
type RoleService interface { // 创建角色 CreateRole(context.Context, *CreateRoleRequest) (*Role, error) // 列表查询 QueryRole(context.Context, *QueryRoleRequest) (*types.Set[*Role], error) // 详情查询 DescribeRole(context.Context, *DescribeRoleRequest) (*Role, error) // 更新角色 UpdateRole(context.Context, *UpdateRoleRequest) (*Role, error) // 删除角色 DeleteRole(context.Context, *DeleteRoleRequest) (*Role, error) }
角色管理
type Service ¶
type Service interface { RoleService ApiPermissionService ViewPermissionService }
func GetService ¶
func GetService() Service
type UpdateApiPermissionRequest ¶
type UpdateApiPermissionRequest struct {
Items []*ApiPermission `json:"items"`
}
type UpdateRoleRequest ¶
type UpdateRoleRequest struct { apps.GetRequest CreateRoleRequest }
type UpdateViewPermission ¶
type UpdateViewPermission struct {
Items []ViewPermission `json:"items"`
}
type ViewPermission ¶
type ViewPermission struct { // 基础数据 apps.ResourceMeta // 角色Id RoleId uint64 `json:"role_id" gorm:"column:role_id;index" description:"Role Id"` // Menu权限定义 ViewPermissionSpec }
func NewViewPermission ¶
func NewViewPermission(roleId uint64, spec *ViewPermissionSpec) *ViewPermission
func (*ViewPermission) TableName ¶
func (r *ViewPermission) TableName() string
type ViewPermissionService ¶
type ViewPermissionService interface { // 查询角色关联的视图权限 QueryViewPermission(context.Context, *QueryViewPermissionRequest) ([]*ViewPermission, error) // 添加角色关联菜单 AddViewPermission(context.Context, *AddViewPermissionRequest) ([]*ViewPermission, error) // 移除角色关联菜单 RemoveViewPermission(context.Context, *RemoveViewPermissionRequest) ([]*ViewPermission, error) // 查询能匹配到视图菜单 QueryMatchedMenu(context.Context, *QueryMatchedMenuRequest) (*types.Set[*view.Menu], error) }
角色菜单管理
type ViewPermissionSpec ¶
type ViewPermissionSpec struct { // 创建者ID CreateBy uint64 `json:"create_by" gorm:"column:create_by" description:"创建者ID" optional:"true"` // 角色描述 Description string `json:"description" gorm:"column:description;type:text" bson:"description" description:"角色描述"` // 服务 Service string `json:"service" gorm:"column:service;type:varchar(100);index" bson:"service" description:"服务名称"` // 页面标签 Label string `json:"label" gorm:"column:label;type:varchar(200);index" description:"页面标签"` // 视图类型 ViewType view.TYPE `json:"view_type" gorm:"column:view_type;type:tinyint(1);index" description:"视图类型"` // 视图路径, 如果是Menu就是Menu路径,如果是Page就是Page路径 ViewPath string `json:"view_path" gorm:"column:view_path;type:varchar(200);index" bson:"view_path" description:"视图路径(可以通配)"` // 其他扩展信息 Extras map[string]string `json:"extras" gorm:"column:extras;serializer:json;type:json" description:"其他扩展信息" optional:"true"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.