-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
51 lines (39 loc) · 1.24 KB
/
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
49
50
51
package servicefoundation
import (
"net/http"
"github.com/julienschmidt/httprouter"
)
type (
// Handle is a function signature for the ServiceFoundation handlers
Handle func(WrappedResponseWriter, *http.Request, RouterParams)
// MetaFunc is a function that returns a map containing meta data used to enrich log messages.
MetaFunc func(*http.Request, RouterParams) map[string]string
// RouterParams is a struct that wraps httprouter.Params
RouterParams struct {
Params httprouter.Params
}
// Router is a struct that wraps httprouter.Router
Router struct {
Router *httprouter.Router
}
// RouterFactory is an interface to create a new Router.
RouterFactory interface {
NewRouter() *Router
}
routerFactoryImpl struct {
}
)
var (
// MethodsForGet contains a slice with the supported http methods for GET.
MethodsForGet = []string{http.MethodGet}
// MethodsForPost contains a slice with the supported http methods for POST.
MethodsForPost = []string{http.MethodPost}
)
// NewRouterFactory instantiates a new RouterFactory implementation.
func NewRouterFactory() RouterFactory {
return &routerFactoryImpl{}
}
/* RouterFactory implementation */
func (r *routerFactoryImpl) NewRouter() *Router {
return &Router{Router: httprouter.New()}
}