This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 479
/
route.go
69 lines (54 loc) · 1.61 KB
/
route.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
68
69
/*
Copyright (c) 2019 the Octant contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package module
import (
"net/http"
"github.com/gorilla/mux"
)
// Router allows registering handlers for a path pattern.
// Routes form a tree and subroutes can be registered.
// Route is a subset of mux.Router.
type Router interface {
Handle(path string, handler http.Handler) Route
HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) Route
PathPrefix(path string) Route
}
// Route allows further tuning the matching of a route.
// Route is a subset of mux.Route.
type Route interface {
Handler(handler http.Handler) Route
HandlerFunc(f func(http.ResponseWriter, *http.Request)) Route
Methods(methods ...string) Route
Subrouter() Router
}
type MuxRouter struct {
*mux.Router
}
type MuxRoute struct {
*mux.Route
}
func (m MuxRoute) Handler(handler http.Handler) Route {
return MuxRoute{m.Route.Handler(handler)}
}
func (m MuxRoute) HandlerFunc(f func(http.ResponseWriter, *http.Request)) Route {
return MuxRoute{m.Route.HandlerFunc(f)}
}
func (m MuxRoute) Methods(methods ...string) Route {
return MuxRoute{m.Route.Methods(methods...)}
}
func (m MuxRoute) Subrouter() Router {
return MuxRouter{m.Route.Subrouter()}
}
func (m MuxRouter) PathPrefix(path string) Route {
r := m.Router.PathPrefix(path)
return MuxRoute{r}
}
func (m MuxRouter) Handle(path string, handler http.Handler) Route {
r := m.Router.Handle(path, handler)
return MuxRoute{r}
}
func (m MuxRouter) HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) Route {
return MuxRoute{m.Router.HandleFunc(path, f)}
}