-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
52 lines (48 loc) · 1.03 KB
/
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
package lr
import (
"fmt"
"net/http"
"testing"
)
func TestServer(t *testing.T) {
//// 接口声明的方式
//var h Server = NewHTTPServer("tcp", ":8080")
//if err := h.Server(); err != nil {
// panic(err)
//}
h := NewHTTPServer("tcp", ":8080")
h.mdls = []Middleware{
func(next HandleFunc) HandleFunc {
return func(ctx *Context) {
fmt.Println("第一个before")
next(ctx)
fmt.Println("第一个after")
}
},
func(next HandleFunc) HandleFunc {
return func(ctx *Context) {
fmt.Println("第二个before")
next(ctx)
fmt.Println("第二个after")
}
},
func(next HandleFunc) HandleFunc {
return func(ctx *Context) {
fmt.Println("第三个before")
fmt.Println("第三个after")
}
},
func(next HandleFunc) HandleFunc {
return func(ctx *Context) {
fmt.Println("第四个before")
}
},
}
//h.GET("/user/profile", func(ctx *Context) {
// fmt.Println("这是一个测试程序")
//})
//if err := h.Server(); err != nil {
// panic(err)
//}
h.ServeHTTP(nil, &http.Request{})
}