label

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 7 Imported by: 0

README

资源标签管理(数据字典)

  • key: value 模式

基于关系型数据库和对应的前端控件进行设计 Tree 结构

Documentation

Index

Constants

View Source
const (
	AppName = "label"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateLabelRequest

type CreateLabelRequest struct {
	CreateBy        string `json:"create_by" bson:"create_by" gorm:"column:create_by;type:varchar(255)" description:"创建者"`
	Domain          string `json:"domain" bson:"domain" gorm:"column:domain;type:varchar(100)" description:"标签的键"`
	Namespace       string `json:"namespace" bson:"namespace" gorm:"column:namespace;type:varchar(100)" description:"标签的命名空间"`
	CreateLabelSpec        // 用户参数
}

func NewCreateLabelRequest

func NewCreateLabelRequest() *CreateLabelRequest

func (*CreateLabelRequest) AddEnumOption

func (c *CreateLabelRequest) AddEnumOption(enums ...*EnumOption) *CreateLabelRequest

func (*CreateLabelRequest) Validate

func (c *CreateLabelRequest) Validate() error

type CreateLabelSpec

type CreateLabelSpec struct {
	Resources    []string      ``                                                                                                                  /* 135-byte string literal not displayed */
	Key          string        `json:"key" bson:"key" gorm:"column:key;type:varchar(255)" description:"标签的键" validate:"required"`                  // 标签的键不允许修改
	KeyDesc      string        `json:"key_desc" bson:"key_desc" gorm:"column:key_desc;type:varchar(255)" description:"标签的键描述" validate:"required"` // 标签的键描述
	Color        string        `json:"color" bson:"color" gorm:"column:color;type:varchar(100)" description:"标签的颜色"`
	ValueType    ValueType     `json:"value_type" bson:"value_type" gorm:"column:value_type;type:varchar(20)" description:"标签的值类型"`   // 标签的值类型
	DefaultValue string        `json:"default_value" bson:"default_value" gorm:"column:default_value;type:text" description:"标签的默认值"` // 标签的默认值
	ValueDesc    string        `json:"value_desc" bson:"value_desc" gorm:"column:value_desc;type:text" description:"标签的值描述"`          // 标签的值描述
	Multiple     bool          `json:"multiple" bson:"multiple" gorm:"column:multiple;type:tinyint(1)" description:"标签的值是否允许多选"`      // 标签的值是否允许多选
	EnumOptions  []*EnumOption ``                                                                                                     // 枚举选项
	/* 135-byte string literal not displayed */
	HttpEnumConfig *HttpEnumConfig `json:"http_enum_config" gorm:"embedded" bson:"http_enum_config" description:"基于 HTTP 的枚举配置"` // 基于 HTTP 的枚举配置
	Example        string          `json:"example" bson:"example" gorm:"column:example;type:text" description:"值的样例"`            // 标签的示例值

	Extras map[string]string `json:"extras" bson:"extras" gorm:"column:extras;type:json;serializer:json" description:"扩展属性"` // 扩展属性

}

type DeleteLabelRequest

type DeleteLabelRequest struct {
	DescribeLabelRequest
}

type DescribeLabelRequest

type DescribeLabelRequest struct {
	Id string `json:"id"` // 标签 id
}

func NewDescribeLabelRequest

func NewDescribeLabelRequest() *DescribeLabelRequest

func (*DescribeLabelRequest) SetId

func (d *DescribeLabelRequest) SetId(Id string)

type EnumOption

type EnumOption struct {
	Label         string            `json:"label" bson:"label"`                           // 选项的说明
	Input         string            `json:"input" bson:"input" validate:"required"`       // 用户输入
	Value         string            `json:"value" bson:"value"`                           // 选项的值 根据 parent.input + children.input 自动生成
	Disabled      bool              `json:"disabled" bson:"disabled"`                     // 是否禁止选中,配合前端 UI 组件使用
	Color         string            `json:"color" bson:"color"`                           // 标签的颜色
	Deprecate     bool              `json:"deprecate" bson:"deprecate"`                   // 是否废弃
	DeprecateDesc string            `json:"deprecate_desc" bson:"deprecate_desc"`         // 废弃说明
	Children      []*EnumOption     `json:"children,omitempty" bson:"children,omitempty"` // 枚举的子选项
	Extensions    map[string]string `json:"extensions" bson:"extensions"`                 // 扩展属性
}

type HttpEnumConfig

type HttpEnumConfig struct {
	Url string `` // 基于枚举的 URL,注意只支持 GET 方法
	/* 127-byte string literal not displayed */
	KeyField string `` // Enum Label映射的字段名
	/* 147-byte string literal not displayed */
	ValueFiled string `json:"enum_label_value" bson:"enum_label_value" gorm:"column:http_enum_config_value_filed;type:varchar(100)"` // Enum Value 映射的字段名
}

type Label

type Label struct {
	apps.ResourceMeta
	CreateLabelRequest `bson:",inline" gorm:"embedded"`
}

func NewLabel

func NewLabel(spc *CreateLabelRequest) (*Label, error)

func (*Label) String

func (l *Label) String() string

func (*Label) TableName

func (l *Label) TableName() string

type QueryLabelRequest

type QueryLabelRequest struct {
	*request.PageRequest
}

func NewQueryLabelRequest

func NewQueryLabelRequest() *QueryLabelRequest

type Service

type Service interface {
	CreateLabel(context.Context, *CreateLabelRequest) (*Label, error)
	UpdateLabel(context.Context, *UpdateLabelRequest) (*Label, error)
	DeleteLabel(context.Context, *DeleteLabelRequest) (*Label, error)
	DescribeLabel(context.Context, *DescribeLabelRequest) (*Label, error)
	QueryLabel(context.Context, *QueryLabelRequest) (*types.Set[*Label], error)
}

func GetService

func GetService() Service

type UpdateLabelRequest

type UpdateLabelRequest struct {
	DescribeLabelRequest
	UpdateBy string           `json:"update_by"` // 更新人
	Spec     *CreateLabelSpec `json:"spec"`      // 标签信息
}

type ValueType

type ValueType string
const (
	ValueTypeText     ValueType = "text"
	ValueTypeBoolean  ValueType = "bool"
	ValueTypeEnum     ValueType = "enum"
	ValueTypeHttpEnum ValueType = "http_enum" // 基于 url 的远程选项拉取,仅存储 url 地址,前端自己处理
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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