Help us shape the future of Go! Take the 2026 Go Developer Survey

tpl

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package tpl 提供同步策略模板库(借鉴 Renovate packageRules/presets)。 模板描述「一批仓库该怎么同步」,可反复套用到任务创建/批量更新。 存储用 data/templates.json:壳层零 DB 迁移,重启可恢复。

Index

Constants

This section is empty.

Variables

View Source
var ErrCycle = errors.New("template extends cycle detected")

ErrCycle 继承链成环。

View Source
var ErrNotFound = errors.New("template not found")

Functions

This section is empty.

Types

type Spec

type Spec struct {
	Cron           string `json:"cron,omitempty"`
	SourceBranch   string `json:"source_branch,omitempty"`
	TargetBranch   string `json:"target_branch,omitempty"`
	Enabled        *bool  `json:"enabled,omitempty"`
	TimeoutSeconds int    `json:"timeout_seconds,omitempty"`
	// RetryMax 失败自动重跑上限(0=沿用全局)
	RetryMax int `json:"retry_max,omitempty"`
}

Spec 策略默认值。非零/非空字段才参与覆盖。

func ResolveSelf

func ResolveSelf(list []Template, id string) (Spec, []string, error)

ResolveSelf 不依赖 Store 的纯解析(测试用)。

func (Spec) Merge

func (base Spec) Merge(child Spec) Spec

Merge 将 child 覆盖到 base(child 非空字段优先)。

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 文件型模板库。

func Open

func Open(path string) (*Store, error)

Open 打开(不存在则空库)。

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete 删除。

func (*Store) Effective

func (s *Store) Effective(id string) (*Template, error)

Effective 返回合并后的模板副本(Spec 已解析,Extends 保留便于展示)。

func (*Store) Get

func (s *Store) Get(id string) (*Template, error)

Get 按 ID 取模板。

func (*Store) List

func (s *Store) List() []Template

List 返回全部模板(副本)。

func (*Store) ListByTag

func (s *Store) ListByTag(tag string) []Template

ListByTag 返回带指定标签的模板。

func (*Store) Resolve

func (s *Store) Resolve(id string) (Spec, []string, error)

Resolve 沿 Extends 链合并 Spec:祖先在前,子覆盖父。 返回 effective Spec 与链路 ID(含自身)。成环返回 ErrCycle。

func (*Store) Upsert

func (s *Store) Upsert(t *Template) (*Template, error)

Upsert 新建或覆盖。

type Template

type Template struct {
	ID          string `gorm:"primaryKey;size:64" json:"id"`
	Name        string `gorm:"size:128;not null" json:"name"`
	Description string `gorm:"size:512" json:"description,omitempty"`
	// Extends 继承的基础模板 ID(Renovate preset 模式)。可链式,须无环。
	Extends string `gorm:"size:64" json:"extends,omitempty"`
	// Match 任务/仓库匹配条件(与 health.Filter 同语义)
	Match map[string][]string `gorm:"serializer:json" json:"match,omitempty"`
	// Spec 套用到任务的默认值(cron/分支/启用);继承时子覆盖父(非空字段)。
	Spec Spec `gorm:"serializer:json" json:"spec"`
	// Tags 便于检索
	Tags      []string  `gorm:"serializer:json" json:"tags,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Template 同步策略模板。 模板同时作为 core 的 ORM 模型(gorm 标签仅为序列化,json 契约不变)。

Jump to

Keyboard shortcuts

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