Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Last active December 19, 2022 11:38
Show Gist options
  • Save karl-gustav/b35007ac413f9aa0936a8e680e34b88e to your computer and use it in GitHub Desktop.
Save karl-gustav/b35007ac413f9aa0936a8e680e34b88e to your computer and use it in GitHub Desktop.
Decode directly from request in golang webserver
var subscription Subscription
err := json.NewDecoder(r.Body).Decode(&subscription)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer r.Body.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment