Skip to content

Commit

Permalink
Remove reference to old, removed gist.
Browse files Browse the repository at this point in the history
Refactor, improve http get error handling.
  • Loading branch information
dmitshur committed Feb 23, 2015
1 parent 8c066ff commit e81c0e3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions gist4670289/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"net/http"
"strings"
//. "github.com/shurcooL/go/gists/gist4668739"
)

// GoKeywords returns a list of Go keywords.
Expand All @@ -19,7 +18,7 @@ func GoKeywords() []string {
panic(err)
}
s := string(b)*/
s := HttpGet("http://golang.org/ref/spec")
s := httpGet("http://golang.org/ref/spec")
//fmt.Println(s)
f := strings.Index(s, "following keywords are reserved and may not be used as identifiers")
s = s[f:]
Expand All @@ -41,20 +40,27 @@ func main() {
fmt.Println(GoKeywords())
}

// Vendor gist4668739 package so this can compile after that package is removed.
// ---

func HttpGet(url string) string {
return string(HttpGetB(url))
}
func HttpGetB(url string) []byte {
r, err := http.Get(url)
func httpGet(url string) string {
b, err := httpGetB(url)
if err != nil {
panic(err)
}
defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
return string(b)
}
func httpGetB(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
panic(err)
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("non-200 status code: %v", resp.StatusCode)
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return b
return b, nil
}

0 comments on commit e81c0e3

Please sign in to comment.