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

Commit

Permalink
cleanups, lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 10, 2017
1 parent 57452bc commit 77d4ffa
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions main.go
Expand Up @@ -123,6 +123,24 @@ func makeName(target string) (string, error) {
return out.String(), err
}

func readURL(loc string) ([]byte, error) {
resp, err := http.Get(loc)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)

// to make errcheck be happy
errc := resp.Body.Close()
if err != nil {
return nil, err
}
if errc != nil {
return nil, errc
}
return body, err
}

func Load(repo string, file string) (*config.Project, error) {
if repo == "" && file == "" {
return nil, fmt.Errorf("Need a repo or file")
Expand All @@ -132,14 +150,9 @@ func Load(repo string, file string) (*config.Project, error) {
}
var body []byte
var err error
log.Printf("Reading %s", file)
if strings.HasPrefix(file, "http") {
log.Printf("Downloading %s", file)
resp, err := http.Get(file)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
body, err = readURL(file)
} else {
body, err = ioutil.ReadFile(file)
}
Expand Down

0 comments on commit 77d4ffa

Please sign in to comment.