node.go 590 B

12345678910111213141516171819202122232425262728293031
  1. package approve_former
  2. import (
  3. "bytes"
  4. "github.com/pkg/errors"
  5. "text/template"
  6. )
  7. type Node interface {
  8. GetDepends() string
  9. GetWhen() string
  10. Render(upperNode Node) (string, error)
  11. }
  12. func render(name string, templateStr string, templateParams map[string]any) (string, error) {
  13. tpl := template.New(name)
  14. tpl.Delims("[[", "]]")
  15. tpl, err := tpl.Parse(templateStr)
  16. if err != nil {
  17. return "", errors.New(err.Error())
  18. }
  19. buffer := &bytes.Buffer{}
  20. err = tpl.Execute(buffer, templateParams)
  21. if err != nil {
  22. return "", errors.New(err.Error())
  23. }
  24. return buffer.String(), nil
  25. }