diff options
| author | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-27 21:03:45 -0700 | 
|---|---|---|
| committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-27 21:04:28 -0700 | 
| commit | cef6e098bb278d50cb2f45f57ed40b3af47d6a74 (patch) | |
| tree | 30399295c85adae450b8966851646037a1f7f5b2 /caddyconfig/httpcaddyfile/directives.go | |
| parent | 260982b2dfc2cbf30c9b6e3a06f54e589344fc41 (diff) | |
Refactor ExtractMatcherSet()
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
| -rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index f82e2a8..03cc8a1 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -161,6 +161,23 @@ func (h Helper) MatcherToken() (caddy.ModuleMap, bool, error) {  	return matcherSetFromMatcherToken(h.Dispenser.Token(), h.matcherDefs, h.warnings)  } +// ExtractMatcherSet is like MatcherToken, except this is a higher-level +// method that returns the matcher set described by the matcher token, +// or nil if there is none, and deletes the matcher token from the +// dispenser and resets it as if this look-ahead never happened. Useful +// when wrapping a route (one or more handlers) in a user-defined matcher. +func (h Helper) ExtractMatcherSet() (caddy.ModuleMap, error) { +	matcherSet, hasMatcher, err := h.MatcherToken() +	if err != nil { +		return nil, err +	} +	if hasMatcher { +		h.Dispenser.Delete() // strip matcher token +	} +	h.Dispenser.Reset() // pretend this lookahead never happened +	return matcherSet, nil +} +  // NewRoute returns config values relevant to creating a new HTTP route.  func (h Helper) NewRoute(matcherSet caddy.ModuleMap,  	handler caddyhttp.MiddlewareHandler) []ConfigValue { | 
