-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
33 lines (26 loc) · 902 Bytes
/
doc.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
/*
The router package provides a simple interface that maps routes to handlers. The router accepts a type argument which must implement the Action interface. This allows clients to define extend and enhance the BaseAction type with additional data and functionality.
Example:
package main
type MyAction struct {
requestId string
*router.BaseAction
}
func Run() {
// Router that defines a context creator that returns a new MyAction for each request.
router := New(func(ac *MyAction) {
ac.requestId = randomString()
}))
// Add an Around handler that sets the requestId header
router.Around(func(ac *MyAction, next func()) {
ac.Response.Header().Add("X-Request-ID", ac.requestId)
next()
})
// Echo back the requestId header
router.Get("/echo", func(ac *MyAction) {
ac.Write([]byte(ac.requestId))
})
http.ListenAndServe(":8080", router)
}
*/
package medium