github.com/tahsinrahman/goreleaser@v0.79.1/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 string
    28  		Tag         string
    29  		Version     string
    30  		Env         map[string]string
    31  	}{
    32  		ProjectName: ctx.Config.ProjectName,
    33  		Tag:         ctx.Git.CurrentTag,
    34  		Version:     ctx.Version,
    35  		Env:         ctx.Env,
    36  	})
    37  	return out.String(), err
    38  }