Created
November 10, 2015 19:59
-
-
Save cdfpaz/c69fce098b90f33d0f04 to your computer and use it in GitHub Desktop.
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 ( | |
"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