1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-04-07 07:10:11 +02:00
Carlos Alexandro Becker 9021160b11 fix: break if env not available
closes #467
2018-01-02 19:01:55 -02:00

38 lines
727 B
Go

package build
import (
"bytes"
"text/template"
"time"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
)
type ldflagsData struct {
Date string
Tag string
Commit string
Version string
Env map[string]string
}
func ldflags(ctx *context.Context, build config.Build) (string, error) {
var data = ldflagsData{
Commit: ctx.Git.Commit,
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
Date: time.Now().UTC().Format(time.RFC3339),
Env: ctx.Env,
}
var out bytes.Buffer
t, err := template.New("ldflags").
Option("missingkey=error").
Parse(build.Ldflags)
if err != nil {
return "", err
}
err = t.Execute(&out, data)
return out.String(), err
}