Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
reduce casting from []byte/string
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Mar 14, 2018
1 parent 33eb6da commit 98d7130
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

// given a template, and a config, generate shell script
func makeShell(tplsrc string, cfg *config.Project) (string, error) {
func makeShell(tplsrc string, cfg *config.Project) ([]byte, error) {

// if we want to add a timestamp in the templates this
// function will generate it
Expand All @@ -29,13 +29,13 @@ func makeShell(tplsrc string, cfg *config.Project) (string, error) {
},
}

var out bytes.Buffer
out := bytes.Buffer{}
t, err := template.New("shell").Funcs(funcMap).Parse(tplsrc)
if err != nil {
return "", err
return nil, err
}
err = t.Execute(&out, cfg)
return out.String(), err
return out.Bytes(), err
}

// converts the given name template to it's equivalent in shell
Expand Down Expand Up @@ -187,7 +187,7 @@ func main() {

kingpin.Parse()
var (
out string
out []byte
err error
)
switch *source {
Expand Down Expand Up @@ -219,7 +219,7 @@ func main() {

// overwrite any existing file
if *force {
if err = ioutil.WriteFile(*output, []byte(out), 0666); err != nil {
if err = ioutil.WriteFile(*output, out, 0666); err != nil {
log.Fatalf("unable to write to %s: %s", *output)
}
return
Expand All @@ -241,10 +241,10 @@ func main() {
checkOrig = false
}
// todo -- is shell file?
if checkOrig && shellEqual(orig, []byte(out)) {
if checkOrig && shellEqual(orig, out) {
return
}
if err := ioutil.WriteFile(*output, []byte(out), 0666); err != nil {
if err := ioutil.WriteFile(*output, out, 0666); err != nil {
log.Fatalf("unable to write to %s: %s", *output, err)
}
}
4 changes: 2 additions & 2 deletions shell_equinoxio.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

// processEquinoxio create a fake goreleaser config for equinox.io
// and use a similar template.
func processEquinoxio(repo string) (string, error) {
func processEquinoxio(repo string) ([]byte, error) {
if repo == "" {
return "", fmt.Errorf("must have repo")
return nil, fmt.Errorf("must have repo")
}
project := config.Project{}
project.Release.GitHub.Owner = path.Dir(repo)
Expand Down
8 changes: 4 additions & 4 deletions shell_godownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"fmt"
)

func processGodownloader(repo string, filename string) (string, error) {
func processGodownloader(repo string, filename string) ([]byte, error) {
cfg, err := Load(repo, filename)
if err != nil {
return "", fmt.Errorf("unable to parse: %s", err)
return nil, fmt.Errorf("unable to parse: %s", err)
}
// get archive name template
archName, err := makeName("NAME=", cfg.Archive.NameTemplate)
cfg.Archive.NameTemplate = archName
if err != nil {
return "", fmt.Errorf("unable generate archive name: %s", err)
return nil, fmt.Errorf("unable generate archive name: %s", err)
}
// get checksum name template
checkName, err := makeName("CHECKSUM=", cfg.Checksum.NameTemplate)
cfg.Checksum.NameTemplate = checkName
if err != nil {
return "", fmt.Errorf("unable generate checksum name: %s", err)
return nil, fmt.Errorf("unable generate checksum name: %s", err)
}

return makeShell(shellGodownloader, cfg)
Expand Down
6 changes: 3 additions & 3 deletions shell_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

// processEquinoxio create a fake goreleaser config for equinox.io
// and use a similar template.
func processRaw(repo string, exe string, nametpl string) (string, error) {
func processRaw(repo string, exe string, nametpl string) ([]byte, error) {
if repo == "" {
return "", fmt.Errorf("must have GitHub owner/repo")
return nil, fmt.Errorf("must have GitHub owner/repo")
}
if exe == "" {
exe = path.Base(repo)
Expand All @@ -23,7 +23,7 @@ func processRaw(repo string, exe string, nametpl string) (string, error) {
// translate golang template to shell string
name, err := makeName("NAME=", nametpl)
if err != nil {
return "", err
return nil, err
}

project := config.Project{}
Expand Down

0 comments on commit 98d7130

Please sign in to comment.