-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
55 lines (45 loc) · 1014 Bytes
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"log"
"testing"
)
type V struct {
Val int `json:"val"`
}
func TestHTTPServer(t *testing.T) {
server := NewHTTPServer("test", "localhost:8080")
server.Get("/query", func(ctx *Context) {
fmt.Println(ctx.QueryValue("a"))
fmt.Println(ctx.QueryValue("c"))
ctx.ResponseWithString(200, "get query val")
})
server.Post("/form", func(ctx *Context) {
val, _ := ctx.FormValue("val").ToInt64()
fmt.Println(val)
fmt.Println(ctx.FormValue("val"))
ctx.ResponseWithString(200, "post form val")
})
server.Post("/", func(ctx *Context) {
a := new(V)
err := ctx.BindJSON(&a)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(a)
ctx.ResponseWithString(200, "post json data")
})
server.PUT("/", func(ctx *Context) {
fmt.Println(123)
ctx.ResponseWithString(200, "put 123")
})
server.Delete("/", func(ctx *Context) {
fmt.Println(123)
ctx.ResponseWithString(200, "delete 123")
})
err := server.Start()
if err != nil {
log.Fatal(err)
}
}