Skip to content

Commit 8a9282f

Browse files
committed
add test
1 parent 990efff commit 8a9282f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

workspace/test/gin.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)