Skip to content

Instantly share code, notes, and snippets.

@cdfpaz
Created November 10, 2015 19:59
Show Gist options
  • Save cdfpaz/c69fce098b90f33d0f04 to your computer and use it in GitHub Desktop.
Save cdfpaz/c69fce098b90f33d0f04 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"encoding/json"
)
type test_struct struct {
Juca string
}
func handler(rw http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
var t test_struct
err := decoder.Decode(&t)
if err != nil {
panic("error decoding json")
fmt.Fprintf(rw, "fail")
} else {
fmt.Fprintf(rw, "ok")
}
log.Println(t.Juca)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8889", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment