node.go 659 B

1234567891011121314151617181920212223242526272829303132
  1. package approve_former
  2. import (
  3. "bytes"
  4. "github.com/pkg/errors"
  5. "text/template"
  6. )
  7. type Noder interface {
  8. // GetWhen 用来指定执行哪个步骤的条件
  9. GetWhen() string
  10. // Render 用来整体渲染步骤
  11. Render(upperNode Noder) (string, error)
  12. }
  13. func render(name string, templateStr string, templateParams map[string]any) (string, error) {
  14. tpl := template.New(name)
  15. tpl.Delims("[[", "]]")
  16. tpl, err := tpl.Parse(templateStr)
  17. if err != nil {
  18. return "", errors.New(err.Error())
  19. }
  20. buffer := &bytes.Buffer{}
  21. err = tpl.Execute(buffer, templateParams)
  22. if err != nil {
  23. return "", errors.New(err.Error())
  24. }
  25. return buffer.String(), nil
  26. }