Skip to content

Instantly share code, notes, and snippets.

@signalpillar
Last active April 28, 2019 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save signalpillar/f333bf9b06f8c983af9dec6d3aeed600 to your computer and use it in GitHub Desktop.
Save signalpillar/f333bf9b06f8c983af9dec6d3aeed600 to your computer and use it in GitHub Desktop.

Http

Error handling

resp, err := http.Get("http://localhost:8080/500")
if err != nil {
	log.Fatal(err)
}
if resp.StatusCode != 200 {
	b, _ := ioutil.ReadAll(resp.Body)
	log.Fatal(string(b))
}

Url

Parse URL param

    keys, ok := r.URL.Query()["key"]
    
    if !ok || len(keys[0]) < 1 {
        log.Println("Url Param 'key' is missing")
        return
    }
@signalpillar
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment