snippet_entity

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryShell  = "shell"
	CategorySQL    = "sql"
	CategoryRedis  = "redis"
	CategoryMongo  = "mongo"
	CategoryK8s    = "k8s"
	CategoryPrompt = "prompt"
)

片段分类常量

View Source
const (
	// SourceUser 用户自创建片段
	SourceUser = "user"
	// SourceExtPrefix 扩展来源前缀,完整 source 形如 "ext:<extension-name>"
	SourceExtPrefix = "ext:"
)

片段来源常量

View Source
const (
	StatusActive  int8 = 1
	StatusDeleted int8 = 2
)

状态常量(遵循仓库软删除约定)

Variables

This section is empty.

Functions

func AllCategories

func AllCategories() []string

AllCategories 返回所有内置片段分类的 ID 列表

func CategoryAssetType

func CategoryAssetType(cat string) string

CategoryAssetType 返回分类绑定的资产类型(asset_entity.AssetType*) prompt 不绑定资产;未知分类返回空字符串。

func IsValidCategory

func IsValidCategory(s string) bool

IsValidCategory 判断分类是否为内置合法分类

Types

type Snippet

type Snippet struct {
	ID           int64      `gorm:"primaryKey"`
	Name         string     `gorm:"size:128;not null;index"`
	Category     string     `gorm:"size:32;not null;index"`
	Content      string     `gorm:"type:text;not null"`
	Description  string     `gorm:"size:512;not null;default:''"`
	LastAssetIDs string     `gorm:"size:1024;not null;default:''"` // comma-separated int64; UI-authoritative
	Source       string     `gorm:"size:64;not null;default:user;index"`
	SourceRef    string     `gorm:"size:128;not null;default:''"`
	UseCount     uint       `gorm:"not null;default:0"`
	LastUsedAt   *time.Time `gorm:"column:last_used_at"`
	Status       int8       `gorm:"not null;default:1;index"`
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

Snippet 片段实体

func (*Snippet) IsReadOnly

func (s *Snippet) IsReadOnly() bool

IsReadOnly 扩展来源的片段不可由用户编辑

func (Snippet) TableName

func (Snippet) TableName() string

TableName GORM 表名

func (*Snippet) Validate

func (s *Snippet) Validate() error

Validate 校验必填字段。

注意:category 仅做"非空"校验;"是否为已注册分类"由 service 层查询 CategoryRegistry 决定(注册表包含内置 5 类 + 运行时已加载扩展声明的分类)。entity 层若直接判定会 拒绝掉扩展分类,破坏 PR 5 的扩展集成。

Jump to

Keyboard shortcuts

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