-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathghttp_test.go
More file actions
76 lines (73 loc) · 1.32 KB
/
ghttp_test.go
File metadata and controls
76 lines (73 loc) · 1.32 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ghttp
import (
"testing"
"fmt"
)
func Test_Server(t *testing.T){
api := New()
m,err := NewMiddleware("/api")
if err != nil{
fmt.Println(err)
return
}
m2,err := NewMiddleware("/api2")
if err != nil{
fmt.Println(err)
return
}
middlewareRouter1 := NewRouter()
middlewareRouter1.POST("/test",test)
middlewareRouter1.PUT("/test",test)
middlewareRouter1.PATCH("/test",test)
m.RegisterFunc(mid)
m.LoadRouter(middlewareRouter1)
//
middlewareRouter2 := NewRouter()
middlewareRouter2.GET("/test",test)
m2.RegisterFunc(mid2)
m2.LoadRouter(middlewareRouter2)
//
apiRouter := NewRouter()
apiRouter.GET("/",index)
//
api.Use(m)
api.Use(m2)
api.LoadRouter(apiRouter)
//
api.ListenAndServe(":9595")
}
func index(ctx *Context){
fmt.Fprint(ctx.ResponseWriter, "Welcome 0000!\n")
}
func mid(ctx *Context){
id,_ := ctx.Input.Int("id")
if id == 100{
ctx.Next()
return
}
}
func mid2(ctx *Context){
id,_ := ctx.Input.Validator("numeric").Int("id")
if id == 200{
ctx.Next()
return
}
var pp = struct {
Error string
}{Error:"mid2 error"}
err := ctx.Json(pp)
if err != nil{
fmt.Println(err)
}
}
func test(ctx *Context){
//id,_ := ctx.Input.Int("id")
//fmt.Fprint(ctx.ResponseWriter, "test!\n")
var pp = struct {
Name string
}{Name:"anjunsang"}
err := ctx.Json(pp)
if err != nil{
fmt.Println(err)
}
}