-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 778 Bytes
/
main.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
package main
import "fmt"
type HandlerFunc func(*Context)
type Context struct {
index int
handlers []HandlerFunc
}
func (c *Context) Next() {
c.index++
for c.index < len(c.handlers) {
c.handlers[c.index](c)
c.index++
}
}
func main() {
c := &Context{
index: -1,
handlers: []HandlerFunc{
func(c *Context) {
fmt.Println("middleware1-start")
c.Next()
fmt.Println("middleware1-end")
},
func(c *Context) {
fmt.Println("-----middleware2-start")
c.Next()
fmt.Println("-----middleware2-end")
},
func(c *Context) {
fmt.Println("---------middleware3-start")
c.Next()
fmt.Println("---------middleware3-end")
},
func(c *Context) {
fmt.Println("------------------" + "hello world")
},
},
}
c.Next()
}