-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgorilla.go
146 lines (120 loc) · 5.82 KB
/
gorilla.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package nape
import (
"fmt"
"net/http"
"net/url"
"github.com/gorilla/mux"
)
func (r *EndpointRegistrationWithMux) add(f func(m *mux.Route) *mux.Route) {
r.muxroutes = append(r.muxroutes, f)
}
// Route returns the *mux.Route that has been registered to this endpoint, if possible.
func (r *EndpointRegistrationWithMux) Route() (*mux.Route, error) {
if !r.bound {
return nil, fmt.Errorf("Registration is not complete for %s", r.path)
}
if r.route == nil {
return nil, fmt.Errorf("No *mux.Route was used to start %s", r.path)
}
return r.route, nil
}
// BuildOnly applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) BuildOnly() *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.BuildOnly() })
return r
}
// BuildVarsFunc applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) BuildVarsFunc(f mux.BuildVarsFunc) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.BuildVarsFunc(f) })
return r
}
// Headers applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Headers(pairs ...string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Headers(pairs...) })
return r
}
// HeadersRegexp applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) HeadersRegexp(pairs ...string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.HeadersRegexp(pairs...) })
return r
}
// Host applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Host(tpl string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Host(tpl) })
return r
}
// MatcherFunc applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) MatcherFunc(f mux.MatcherFunc) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.MatcherFunc(f) })
return r
}
// Methods applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Methods(methods ...string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Methods(methods...) })
return r
}
// Name applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Name(name string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Name(name) })
return r
}
// Path applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Path(tpl string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Path(tpl) })
return r
}
// PathPrefix applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) PathPrefix(tpl string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.PathPrefix(tpl) })
return r
}
// Queries applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Queries(pairs ...string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Queries(pairs...) })
return r
}
// Schemes applies the mux.Route method of the same name to this endpoint when the endpoint is initialized.
func (r *EndpointRegistrationWithMux) Schemes(schemes ...string) *EndpointRegistrationWithMux {
r.add(func(m *mux.Route) *mux.Route { return m.Schemes(schemes...) })
return r
}
// GetError calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) GetError() error {
return r.err
}
// GetHandler calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) GetHandler() http.Handler {
return r.route.GetHandler()
}
// GetHostTemplate calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) GetHostTemplate() (string, error) {
return r.route.GetHostTemplate()
}
// GetName calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) GetName() string {
return r.route.GetName()
}
// GetPathTemplate calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) GetPathTemplate() (string, error) {
return r.route.GetPathTemplate()
}
// Match calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) Match(req *http.Request, match *mux.RouteMatch) bool {
return r.route.Match(req, match)
}
// SkipClean calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) SkipClean() bool {
return r.route.SkipClean()
}
// URL calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) URL(pairs ...string) (*url.URL, error) {
return r.route.URL(pairs...)
}
// URLHost calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) URLHost(pairs ...string) (*url.URL, error) {
return r.route.URLHost(pairs...)
}
// URLPath calls the mux.Route method of the same name on the route created for this endpoint.
func (r *EndpointRegistrationWithMux) URLPath(pairs ...string) (*url.URL, error) {
return r.route.URLPath(pairs...)
}