/
main.go
53 lines (41 loc) · 1.02 KB
/
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
47
48
49
50
51
52
53
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/nightshaders/ywebserver/decorator"
)
func main() {
// server.NewCli(ExampleServe).Run(os.Args)
var unauth decorator.Decorator = decorator.NewPipeline().
Next(ProvideErrorHandling).
Next(ProvideSession).
Next(ProvideUserProfile)
handler := unauth.Handle(H{})
res := httptest.NewRecorder()
req := &http.Request{}
handler(res, req)
}
type H struct{}
func (h H) Handle(p decorator.Params) error {
fmt.Println("Handle")
return nil
}
func ProvideErrorHandling(w decorator.WebHandler) decorator.WebHandler {
return func(p decorator.Params) (err error) {
fmt.Println("ErrorHandling")
return w.Handle(p)
}
}
func ProvideSession(w decorator.WebHandler) decorator.WebHandler {
return func(p decorator.Params) (err error) {
fmt.Println("Session")
return w.Handle(p)
}
}
func ProvideUserProfile(w decorator.WebHandler) decorator.WebHandler {
return func(p decorator.Params) (err error) {
fmt.Println("UserProfile")
return w.Handle(p)
}
}