-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
48 lines (37 loc) · 828 Bytes
/
router.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
package router
import (
"net/http"
"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"
"github.com/justinas/alice"
)
var (
r RouterInfo
)
const (
params = "params"
)
// RouteInfo is the details
type RouterInfo struct {
Router *httprouter.Router
}
// Set up the router
func init() {
r.Router = httprouter.New()
}
// ReadConfig returns the information
func ReadConfig() RouterInfo {
return r
}
// Instance returns the router
func Instance() *httprouter.Router {
return r.Router
}
// Context returns the URL parameters
func Params(r *http.Request) httprouter.Params {
return context.Get(r, params).(httprouter.Params)
}
// Chain returns handle with chaining using Alice
func Chain(fn http.HandlerFunc, c ...alice.Constructor) httprouter.Handle {
return Handler(alice.New(c...).ThenFunc(fn))
}