diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-30 21:12:03 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-02 08:09:42 +1000 |
commit | d4ab607d0dd94f73eb1dcd4ba9842eb86b6aa0f4 (patch) | |
tree | 4cb72d33183f60fc8a943dd35d7299ce07d44cee /pkg/utils | |
parent | ea307c8d94623bd0279297db2cf3990492998ab4 (diff) |
allow adding a submodule
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/utils.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 12c89e5da..b535431ee 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -1,6 +1,7 @@ package utils import ( + "bytes" "encoding/json" "fmt" "log" @@ -9,6 +10,7 @@ import ( "regexp" "strconv" "strings" + "text/template" "time" "github.com/fatih/color" @@ -343,3 +345,17 @@ func MustConvertToInt(s string) int { } return i } + +func ResolveTemplate(templateStr string, object interface{}) (string, error) { + tmpl, err := template.New("template").Parse(templateStr) + if err != nil { + return "", err + } + + var buf bytes.Buffer + if err := tmpl.Execute(&buf, object); err != nil { + return "", err + } + + return buf.String(), nil +} |