Documentation
¶
Index ¶
- Variables
- func GoodName(name string) bool
- func Plaintext(text string) (string, error)
- func ToBuffer(tmpl *template.Template, text string, data any) (*bytes.Buffer, error)
- func ToString(tmpl *template.Template, text string, data any) (string, error)
- func Unmarshal(uses string, tmpl *Template) error
- type DatabaseDecoder
- type Env
- type FileDecoder
- type SafeTemplate
- type Step
- type Template
- type Unmarshaler
- type Version
- func (v Version) Equal(other Version) bool
- func (v Version) IsZero() bool
- func (v Version) Less(other Version) bool
- func (v Version) MarshalJSON() ([]byte, error)
- func (v Version) MarshalText() ([]byte, error)
- func (v Version) MarshalYAML() (any, error)
- func (v Version) String() string
- func (v *Version) UnmarshalJSON(b []byte) error
- func (v *Version) UnmarshalText(data []byte) error
- func (v *Version) UnmarshalYAML(value *yaml.Node) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyInput = errors.New("template: empty input") ErrNotString = errors.New("template: version must be a string") ErrInvalidFormat = errors.New("template: invalid version format: expected vX.Y.Z") ErrEmptyComponent = errors.New("template: empty version component") )
View Source
var BuiltinFuncMap = template.FuncMap{ "json": func(v any) (string, error) { b, err := json.Marshal(v) return string(b), err }, "gjson": func(json, path string) any { return gjson.Get(json, path).Value() }, "gjson2": func(json, path string) (any, error) { if r := gjson.Get(json, path); r.Exists() { return r.Value(), nil } return nil, fmt.Errorf("path not found: \"%s\"", path) }, "base64encode": func(s string) string { return base64.StdEncoding.EncodeToString([]byte(s)) }, "base64decode": func(s string) (string, error) { data, err := base64.StdEncoding.DecodeString(s) if err != nil { return "", err } return string(data), nil }, "plaintext": Plaintext, }
内置函数
View Source
var ErrEmptyURL = errors.New("template: step URL is empty")
View Source
var ErrInvalidDecoder = errors.New("template: invalid Decoder")
Functions ¶
Types ¶
type DatabaseDecoder ¶
数据库解码器 可以从数据库 steps 表中解析模板
func (*DatabaseDecoder) UnmarshalTemplate ¶
func (d *DatabaseDecoder) UnmarshalTemplate(uses string, tmpl *Template) error
type FileDecoder ¶
type FileDecoder struct{}
文件解码器 可以从 JSON 和 YAML 文件中解析模板
func (FileDecoder) UnmarshalTemplate ¶
func (FileDecoder) UnmarshalTemplate(uses string, tmpl *Template) error
type SafeTemplate ¶
type SafeTemplate struct {
// contains filtered or unexported fields
}
并发安全模板
func NewSafeTemplate ¶
func NewSafeTemplate(v any) *SafeTemplate
type Step ¶
type Step struct {
Template `yaml:",inline"`
TemplateID uint64 `json:"-" yaml:"-"` // 模板外键
Skip string `json:"skip" yaml:"skip"` // 跳过步骤
Uses string `json:"uses" yaml:"uses"` // 使用模板
Method string `json:"method" yaml:"method"` // 请求方法
URL string `json:"url" yaml:"url"` // 请求地址
Body string `json:"body" yaml:"body"` // 请求内容
Header Env `json:"header" yaml:"header" gorm:"serializer:json"` // 请求头部
Set Env `json:"set" yaml:"set" gorm:"serializer:json"` // 设置环境变量
Out Env `json:"out" yaml:"out" gorm:"serializer:json"` // 导出环境变量
}
步骤
type Template ¶
type Template struct {
ID uint64 `json:"-" yaml:"-" gorm:"primaryKey;autoIncrement"` // 模板标识符
Description string `json:"description" yaml:"description"` // 模板介绍
Author string `json:"author" yaml:"author" gorm:"index:idx_uses,priority:1"` // 模板作者
Namespace string `json:"namespace" yaml:"namespace" gorm:"index:idx_uses,priority:2"` // 模板命名
Version Version `json:"version" yaml:"version" gorm:"embedded"` // 模板版本
Env Env `json:"env" yaml:"env" gorm:"serializer:json"` // 模板环境
Steps []Step `json:"steps" yaml:"steps" gorm:"foreignkey:TemplateID"` // 模板步骤
}
模板
func (Template) StringIndent ¶
type Unmarshaler ¶
var Decoder Unmarshaler
type Version ¶
type Version struct {
// 主版本号
// 这个数字的变化表示了一个重大更新,通常伴随着不兼容的API变更或者重大的功能改进
Major uint64 `gorm:"index:idx_uses,priority:3"`
// 次版本号
// 这个数字的变化表示了向后兼容的新功能添加,通常是对现有功能的扩展
Minor uint64 `gorm:"index:idx_uses,priority:4"`
// 修订号
// 这个数字的变化表示了向后兼容的问题修复,通常是对现有功能的错误修正
Patch uint64 `gorm:"index:idx_uses,priority:5"`
}
版本号
func (Version) MarshalJSON ¶
func (Version) MarshalText ¶
func (Version) MarshalYAML ¶
func (*Version) UnmarshalJSON ¶
func (*Version) UnmarshalText ¶
Click to show internal directories.
Click to hide internal directories.