Documentation ¶
Index ¶
- Variables
- func CopyFile(dstName, srcName string) (written int64, err error)
- type Alert
- type Alerts
- type Config
- type Data
- type KV
- type Option
- type Pair
- type Pairs
- type Template
- func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)
- func (t *Template) Data(recv string, groupLabels label.LabelSet, alerts ...*alert.Alert) *Data
- func (t *Template) EnableTplDataFile(tplPath string) error
- func (t *Template) ExecuteHTMLString(html string, data interface{}) (string, error)
- func (t *Template) ExecuteTextString(text string, data interface{}) (string, error)
- func (t *Template) GetTplDataPath(tempPath string) string
- func (t *Template) GetTplTempPath(tempPath string) string
- func (t *Template) Parse(text string) (*Template, error)
- func (t *Template) ParseDir(path string) (*Template, error)
- func (t *Template) ParseFS(fsys fs.FS, patterns ...string) (*Template, error)
- func (t *Template) ParseFiles(filenames ...string) (*Template, error)
- func (t *Template) ParseGlob(pattern string) (*Template, error)
- func (t *Template) RemoveTplDataFile(tplPath string) error
- func (t *Template) ValidateFilePath(ctx context.Context, path string, kind TplPathKind) error
- type TplPathKind
Constants ¶
This section is empty.
Variables ¶
var DefaultFuncs = map[string]any{ "toUpper": strings.ToUpper, "toLower": strings.ToLower, "title": func(text string) string { return cases.Title(language.AmericanEnglish).String(text) }, "trimSpace": strings.TrimSpace, "join": func(sep string, s []string) string { return strings.Join(s, sep) }, "match": regexp.MatchString, "safeHtml": func(text string) tmplhtml.HTML { return tmplhtml.HTML(text) }, "reReplaceAll": func(pattern, repl, text string) string { re := regexp.MustCompile(pattern) return re.ReplaceAllString(text, repl) }, "stringSlice": func(s ...string) []string { return s }, "markdown": markdownEscapeString, "toJSON": toJson, }
Functions ¶
Types ¶
type Alert ¶
type Alert struct { Status string `json:"status"` Labels KV `json:"labels"` Annotations KV `json:"annotations"` StartsAt time.Time `json:"startsAt"` EndsAt time.Time `json:"endsAt"` GeneratorURL string `json:"generatorURL"` Fingerprint string `json:"fingerprint"` }
Alert holds one alert for notification templates.
type Alerts ¶
type Alerts []Alert
Alerts is a list of Alert objects.
type Config ¶
type Config struct { // path for custom template BaseDir string // path for temporary template TmpDir string // path for active template dir DataDir string // path for attachment AttachmentDir string }
Config stores configuration for template.
type Data ¶
type Data struct { Receiver string `json:"receiver"` Status string `json:"status"` Alerts Alerts `json:"alerts"` GroupLabels KV `json:"groupLabels"` CommonLabels KV `json:"commonLabels"` CommonAnnotations KV `json:"commonAnnotations"` ExternalURL string `json:"externalURL"` }
Data is the data passed to notification templates and webhook pushes.
End-users should not be exposed to Go's type system, as this will confuse them and prevent simple things like simple equality checks to fail. Map everything to float64/string.
type KV ¶
func (KV) SortedPairs ¶
SortedPairs returns a sorted list of key/value pairs.
type Template ¶
Template bundles a text and a html template instance.
func MustParse ¶
MustParse is a helper that wraps a call to a function returning (*Template, error) and panics if the error is non-nil.
func New ¶
New returns a new Template with the DefaultFuncs added. The DefaultFuncs have precedence over any added custom functions. Options allow customization of the text and html templates in given order.
func (*Template) AddParseTree ¶
AddParseTree adds the given parse tree to the template.
func (*Template) EnableTplDataFile ¶
EnableTplDataFile 启用模板文件 tplPath 为temp文件路径
func (*Template) ExecuteHTMLString ¶
ExecuteHTMLString needs a meaningful doc comment (TODO(fabxc)).
func (*Template) ExecuteTextString ¶
ExecuteTextString needs a meaningful doc comment (TODO(fabxc)).
func (*Template) GetTplDataPath ¶
GetTplDataPath 将tpl临时文件路径转为正式存储路径
func (*Template) GetTplTempPath ¶
GetTplTempPath 获取tpl正式文件路径
func (*Template) ParseDir ¶
ParseDir walks on the given dir path and parses the given matches with aren't Go files.
func (*Template) ParseFS ¶
ParseFS is like ParseFiles or ParseGlob but reads from the file system fsys instead of the host operating system's file system.
func (*Template) ParseFiles ¶
ParseFiles parses a list of files as templates and associate them with t. Each file can be a standalone template.
func (*Template) ParseGlob ¶
ParseGlob parses the files that match the given pattern as templates and associate them with t.
func (*Template) RemoveTplDataFile ¶
RemoveTplDataFile 移除data目录模板 tplPath 为temp文件路径
func (*Template) ValidateFilePath ¶
ValidateFilePath Verify compliance with file service conventions. path rule: {PathKind}/{tenantId}/{xxx}/{filename}
type TplPathKind ¶
type TplPathKind int
const ( TplPathKindData TplPathKind = iota TplPathKindTmp TplPathKindAttachment )