Skip to content

Instantly share code, notes, and snippets.

@nesv
Created January 19, 2016 21:26
Show Gist options
  • Save nesv/8ccbd9fdc414367d3531 to your computer and use it in GitHub Desktop.
Save nesv/8ccbd9fdc414367d3531 to your computer and use it in GitHub Desktop.
Sample HTTP client
package main
import (
"log"
"net/http"
"net/url"
"time"
)
func main() {
delay := time.Duration(1) * time.Second
resp, err := http.PostForm("http://your-server/work", url.Values{
"delay": delay.String(),
"name": "Nick",
})
if err != nil {
log.Fatalln(err)
}
defer resp.Close()
switch v := resp.StatusCode; v {
case http.StatusCreated:
log.Println("ok")
return
}
log.Fatalln("unexpected status from server:", resp.Status)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment