MCPcopy
hub / github.com/gorilla/mux / addRegexpMatcher

Method addRegexpMatcher

route.go:184–229  ·  view source on GitHub ↗

addRegexpMatcher adds a host or path matcher and builder to a route.

(tpl string, typ regexpType)

Source from the content-addressed store, hash-verified

182
183// addRegexpMatcher adds a host or path matcher and builder to a route.
184func (r *Route) addRegexpMatcher(tpl string, typ regexpType) error {
185 if r.err != nil {
186 return r.err
187 }
188 if typ == regexpTypePath || typ == regexpTypePrefix {
189 if len(tpl) > 0 && tpl[0] != '/' {
190 return fmt.Errorf("mux: path must start with a slash, got %q", tpl)
191 }
192 if r.regexp.path != nil {
193 tpl = strings.TrimRight(r.regexp.path.template, "/") + tpl
194 }
195 }
196 rr, err := newRouteRegexp(tpl, typ, routeRegexpOptions{
197 strictSlash: r.strictSlash,
198 useEncodedPath: r.useEncodedPath,
199 })
200 if err != nil {
201 return err
202 }
203 for _, q := range r.regexp.queries {
204 if err = uniqueVars(rr.varsN, q.varsN); err != nil {
205 return err
206 }
207 }
208 if typ == regexpTypeHost {
209 if r.regexp.path != nil {
210 if err = uniqueVars(rr.varsN, r.regexp.path.varsN); err != nil {
211 return err
212 }
213 }
214 r.regexp.host = rr
215 } else {
216 if r.regexp.host != nil {
217 if err = uniqueVars(rr.varsN, r.regexp.host.varsN); err != nil {
218 return err
219 }
220 }
221 if typ == regexpTypeQuery {
222 r.regexp.queries = append(r.regexp.queries, rr)
223 } else {
224 r.regexp.path = rr
225 }
226 }
227 r.addMatcher(rr)
228 return nil
229}
230
231// Headers --------------------------------------------------------------------
232

Callers 4

HostMethod · 0.95
PathMethod · 0.95
PathPrefixMethod · 0.95
QueriesMethod · 0.95

Calls 3

addMatcherMethod · 0.95
newRouteRegexpFunction · 0.85
uniqueVarsFunction · 0.85

Tested by

no test coverage detected