/
chain.go
67 lines (52 loc) · 1.03 KB
/
chain.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
56
57
58
59
60
61
62
63
64
65
66
67
package http
type HandlerChain []HandlerFunction
/*
func NewHandlerChain(functions []HandlerFunction) *HandlerChain {
return &HandlerChain{
functions: functions,
size: len(functions),
}
}
func (c *HandlerChain) Invoke(ctx Context) {
if ctx == nil || len(c.functions) == 0 {
return
}
nextHandler := ctx.nextHandler()
if ctx.IsCompleted() || ctx.IsAborted() || c.size <= nextHandler {
return
}
next := c.functions[nextHandler]
nextHandler++
ctx.setNextHandler(nextHandler)
err := next(ctx, c)
if err != nil {
ctx.setErr(err)
}
if ctx.IsCompleted() || ctx.IsAborted() {
return
}
if nextHandler != c.size {
ctx.Abort()
} else {
ctx.complete()
}
}*/
/*
func (c *HandlerChain) Invoke(ctx *Context) {
if ctx == nil || len(c.functions) == 0 {
return
}
if ctx.HandlerChain == nil {
ctx.HandlerChain = c
}
nextHandler := ctx.nextHandler()
next := c.functions[nextHandler]
ctx.handlerIndex = 1
err := next(ctx, &ctx.delegate)
if err != nil {
ctx.err = err
}
ctx.completed = true
return
}
*/