1234567891011121314151617181920212223242526272829303132 |
- package approve_former
- import (
- "bytes"
- "github.com/pkg/errors"
- "text/template"
- )
- type Noder interface {
- // GetWhen 用来指定执行哪个步骤的条件
- GetWhen() string
- // Render 用来整体渲染步骤
- Render(upperNode Noder) (string, error)
- }
- func render(name string, templateStr string, templateParams map[string]any) (string, error) {
- tpl := template.New(name)
- tpl.Delims("[[", "]]")
- tpl, err := tpl.Parse(templateStr)
- if err != nil {
- return "", errors.New(err.Error())
- }
- buffer := &bytes.Buffer{}
- err = tpl.Execute(buffer, templateParams)
- if err != nil {
- return "", errors.New(err.Error())
- }
- return buffer.String(), nil
- }
|