resource

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResourceRepository

func NewResourceRepository(db *gorm.DB) domain.Repository

NewResourceRepository 创建 Resource 仓储

Types

type Mapper

type Mapper struct{}

Mapper Resource BO 和 PO 转换器

func NewMapper

func NewMapper() *Mapper

NewMapper 创建 Mapper

func (*Mapper) ToBO

func (m *Mapper) ToBO(po *ResourcePO) *resource.Resource

ToBO 将 PO 转换为 BO

func (*Mapper) ToBOList

func (m *Mapper) ToBOList(pos []*ResourcePO) []*resource.Resource

ToBOList 将 PO 列表转换为 BO 列表

func (*Mapper) ToPO

func (m *Mapper) ToPO(bo *resource.Resource) *ResourcePO

ToPO 将 BO 转换为 PO

type ResourcePO

type ResourcePO struct {
	base.AuditFields
	Key         string `gorm:"column:key;type:varchar(128);not null;uniqueIndex"`
	DisplayName string `gorm:"column:display_name;type:varchar(128)"`
	AppName     string `gorm:"column:app_name;type:varchar(32);index"`
	Domain      string `gorm:"column:domain;type:varchar(32);index"`
	Type        string `gorm:"column:type;type:varchar(32);index"`
	Actions     string `gorm:"column:actions;type:text"` // JSON array string
	Description string `gorm:"column:description;type:varchar(512)"`
}

ResourcePO 资源持久化对象

func (*ResourcePO) BeforeCreate

func (p *ResourcePO) BeforeCreate(tx *gorm.DB) error

BeforeCreate 在创建前设置信息

func (*ResourcePO) BeforeUpdate

func (r *ResourcePO) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate 在更新前设置信息

func (ResourcePO) TableName

func (ResourcePO) TableName() string

TableName 指定表名

type ResourceRepository

type ResourceRepository struct {
	mysql.BaseRepository[*ResourcePO]
	// contains filtered or unexported fields
}

ResourceRepository Resource 仓储实现

func (*ResourceRepository) Create

func (r *ResourceRepository) Create(ctx context.Context, res *domain.Resource) error

Create 创建新资源

func (*ResourceRepository) Delete

Delete 删除资源(软删除)

func (*ResourceRepository) FindByID

FindByID 根据ID查找资源

func (*ResourceRepository) FindByKey

func (r *ResourceRepository) FindByKey(ctx context.Context, key string) (*domain.Resource, error)

FindByKey 根据资源键查找

func (*ResourceRepository) List

func (r *ResourceRepository) List(ctx context.Context, offset, limit int) ([]*domain.Resource, int64, error)

List 列出所有资源

func (*ResourceRepository) ListByApp

func (r *ResourceRepository) ListByApp(ctx context.Context, appName string, offset, limit int) ([]*domain.Resource, int64, error)

ListByApp 列出应用的资源

func (*ResourceRepository) ListByDomain

func (r *ResourceRepository) ListByDomain(ctx context.Context, domain string, offset, limit int) ([]*domain.Resource, int64, error)

ListByDomain 列出业务域的资源

func (*ResourceRepository) Update

func (r *ResourceRepository) Update(ctx context.Context, res *domain.Resource) error

Update 更新资源

func (*ResourceRepository) ValidateAction

func (r *ResourceRepository) ValidateAction(ctx context.Context, resourceKey, action string) (bool, error)

ValidateAction 校验动作是否在资源的允许列表中

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL