File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ // gin.go
2+ package main
3+
4+ import (
5+ "encoding/json"
6+ "fmt"
7+ "log"
8+ "net/http"
9+ )
10+
11+ type Data struct {
12+ Name string `json:"name"`
13+ Info struct {
14+ Age int `json:"age"`
15+ } `json:"info"`
16+ }
17+
18+ func AddUser (w http.ResponseWriter , r * http.Request ) {
19+ fmt .Println (r .Header ["Content-Type" ])
20+ var data Data
21+ err := json .NewDecoder (r .Body ).Decode (& data )
22+ if err != nil {
23+ fmt .Println (err )
24+ }
25+ fmt .Println (data )
26+ //data, err := ioutil.ReadAll(r.Body)
27+
28+ fmt .Fprint (w , "Hello!" )
29+ }
30+
31+ func index (w http.ResponseWriter , r * http.Request ) {
32+ fmt .Fprint (w , "index" )
33+ }
34+
35+ func main () {
36+ http .HandleFunc ("/" , index )
37+ http .HandleFunc ("/user" , AddUser )
38+ log .Fatal (http .ListenAndServe ("localhost:4000" , nil ))
39+ }
You can’t perform that action at this time.
0 commit comments