1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/config/archive_config.go

46 lines
1.0 KiB
Go
Raw Normal View History

2017-01-11 18:47:56 +02:00
package config
import (
"bytes"
"html/template"
)
// ArchiveConfig config used for the archive
type ArchiveConfig struct {
Format string
NameTemplate string `yaml:"name_template"`
2017-01-11 23:24:17 +02:00
Replacements map[string]string
2017-01-11 18:47:56 +02:00
}
type archiveNameData struct {
Os string
Arch string
Version string
BinaryName string
}
// ArchiveName following the given template
func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
var data = archiveNameData{
2017-01-11 23:24:17 +02:00
Os: replace(config.Archive.Replacements, goos),
Arch: replace(config.Archive.Replacements, goarch),
2017-01-11 18:47:56 +02:00
Version: config.Git.CurrentTag,
BinaryName: config.BinaryName,
}
var out bytes.Buffer
t, err := template.New(data.BinaryName).Parse(config.Archive.NameTemplate)
if err != nil {
return "", err
}
err = t.Execute(&out, data)
return out.String(), err
}
2017-01-11 23:24:17 +02:00
func replace(replacements map[string]string, original string) string {
result := replacements[original]
if result == "" {
return original
}
return result
}