github.com/elyscape/goreleaser@v0.66.1-0.20180515111211-5252f74ade63/internal/nametemplate/name.go (about) 1 // Package nametemplate provides common template function for releases and etc. 2 package nametemplate 3 4 import ( 5 "bytes" 6 "text/template" 7 "time" 8 9 "github.com/goreleaser/goreleaser/context" 10 ) 11 12 // Apply applies the given name template using the context as source. 13 func Apply(ctx *context.Context, tmpl string) (string, error) { 14 var out bytes.Buffer 15 t, err := template.New("release"). 16 Option("missingkey=error"). 17 Funcs(template.FuncMap{ 18 "time": func(s string) string { 19 return time.Now().UTC().Format(s) 20 }, 21 }). 22 Parse(tmpl) 23 if err != nil { 24 return "", err 25 } 26 err = t.Execute(&out, struct { 27 ProjectName, Tag, Version string 28 }{ 29 ProjectName: ctx.Config.ProjectName, 30 Tag: ctx.Git.CurrentTag, 31 Version: ctx.Version, 32 }) 33 return out.String(), err 34 }