Skip to content

Instantly share code, notes, and snippets.

@ethanliew
Forked from andreagrandi/parse_json_post.go
Created September 11, 2021 13:21
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 ethanliew/8de48050e4feb73a4c2a023ef3f9120e to your computer and use it in GitHub Desktop.
Save ethanliew/8de48050e4feb73a4c2a023ef3f9120e to your computer and use it in GitHub Desktop.
Parse a JSON http POST in GoLang
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type test_struct struct {
Test string
}
func parseGhPost(rw http.ResponseWriter, request *http.Request) {
decoder := json.NewDecoder(request.Body)
var t test_struct
err := decoder.Decode(&t)
if err != nil {
panic(err)
}
fmt.Println(t.Test)
}
func main() {
http.HandleFunc("/", parseGhPost)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment