Skip to content

Instantly share code, notes, and snippets.

@brpaz
Created March 16, 2019 09:58
Show Gist options
  • Save brpaz/cb02df75cd3167f752c41ca1776012bb to your computer and use it in GitHub Desktop.
Save brpaz/cb02df75cd3167f752c41ca1776012bb to your computer and use it in GitHub Desktop.
func main() {
u := User{Id: "US123", Balance: 8}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(u)
res, _ := http.Post("https://httpbin.org/post", "application/json; charset=utf-8", b)
var body struct {
// httpbin.org sends back key/value pairs, no map[string][]string
Headers map[string]string `json:"headers"`
Origin string `json:"origin"`
}
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment