-
-
Save kenwoodjw/5d0aa525475ac5f0bf50657c77d00adf to your computer and use it in GitHub Desktop.
Parse a JSON http POST in GoLang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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