caddyhttp: Rename MatchNegate type to MatchNot type

This is more congruent with its module name. A change that affects only
code, not configurations.
This commit is contained in:
Matthew Holt 2020-03-30 11:53:19 -06:00
parent 37aa516a6e
commit ac65f690ae
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with 15 additions and 15 deletions

View File

@ -99,10 +99,10 @@ type (
cidrs []*net.IPNet cidrs []*net.IPNet
} }
// MatchNegate matches requests by negating its matchers' results. // MatchNot matches requests by negating its matchers' results.
// To use, simply specify a set of matchers like you normally would; // To use, simply specify a set of matchers like you normally would;
// the only difference is that their result will be negated. // the only difference is that their result will be negated.
MatchNegate struct { MatchNot struct {
MatchersRaw caddy.ModuleMap `json:"-" caddy:"namespace=http.matchers"` MatchersRaw caddy.ModuleMap `json:"-" caddy:"namespace=http.matchers"`
Matchers MatcherSet `json:"-"` Matchers MatcherSet `json:"-"`
@ -119,7 +119,7 @@ func init() {
caddy.RegisterModule(MatchHeaderRE{}) caddy.RegisterModule(MatchHeaderRE{})
caddy.RegisterModule(new(MatchProtocol)) caddy.RegisterModule(new(MatchProtocol))
caddy.RegisterModule(MatchRemoteIP{}) caddy.RegisterModule(MatchRemoteIP{})
caddy.RegisterModule(MatchNegate{}) caddy.RegisterModule(MatchNot{})
} }
// CaddyModule returns the Caddy module information. // CaddyModule returns the Caddy module information.
@ -531,10 +531,10 @@ func (m *MatchProtocol) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
} }
// CaddyModule returns the Caddy module information. // CaddyModule returns the Caddy module information.
func (MatchNegate) CaddyModule() caddy.ModuleInfo { func (MatchNot) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{ return caddy.ModuleInfo{
ID: "http.matchers.not", ID: "http.matchers.not",
New: func() caddy.Module { return new(MatchNegate) }, New: func() caddy.Module { return new(MatchNot) },
} }
} }
@ -542,17 +542,17 @@ func (MatchNegate) CaddyModule() caddy.ModuleInfo {
// This is done because we cannot embed the map directly into // This is done because we cannot embed the map directly into
// the struct, but we need a struct because we need another // the struct, but we need a struct because we need another
// field just for the provisioned modules. // field just for the provisioned modules.
func (m *MatchNegate) UnmarshalJSON(data []byte) error { func (m *MatchNot) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &m.MatchersRaw) return json.Unmarshal(data, &m.MatchersRaw)
} }
// MarshalJSON marshals m's matchers. // MarshalJSON marshals m's matchers.
func (m MatchNegate) MarshalJSON() ([]byte, error) { func (m MatchNot) MarshalJSON() ([]byte, error) {
return json.Marshal(m.MatchersRaw) return json.Marshal(m.MatchersRaw)
} }
// UnmarshalCaddyfile implements caddyfile.Unmarshaler. // UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (m *MatchNegate) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// first, unmarshal each matcher in the set from its tokens // first, unmarshal each matcher in the set from its tokens
matcherMap := make(map[string]RequestMatcher) matcherMap := make(map[string]RequestMatcher)
@ -593,7 +593,7 @@ func (m *MatchNegate) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
} }
// Provision loads the matcher modules to be negated. // Provision loads the matcher modules to be negated.
func (m *MatchNegate) Provision(ctx caddy.Context) error { func (m *MatchNot) Provision(ctx caddy.Context) error {
mods, err := ctx.LoadModule(m, "MatchersRaw") mods, err := ctx.LoadModule(m, "MatchersRaw")
if err != nil { if err != nil {
return fmt.Errorf("loading matchers: %v", err) return fmt.Errorf("loading matchers: %v", err)
@ -606,7 +606,7 @@ func (m *MatchNegate) Provision(ctx caddy.Context) error {
// Match returns true if r matches m. Since this matcher negates the // Match returns true if r matches m. Since this matcher negates the
// embedded matchers, false is returned if any of its matchers match. // embedded matchers, false is returned if any of its matchers match.
func (m MatchNegate) Match(r *http.Request) bool { func (m MatchNot) Match(r *http.Request) bool {
return !m.Matchers.Match(r) return !m.Matchers.Match(r)
} }
@ -851,8 +851,8 @@ var (
_ RequestMatcher = (*MatchProtocol)(nil) _ RequestMatcher = (*MatchProtocol)(nil)
_ RequestMatcher = (*MatchRemoteIP)(nil) _ RequestMatcher = (*MatchRemoteIP)(nil)
_ caddy.Provisioner = (*MatchRemoteIP)(nil) _ caddy.Provisioner = (*MatchRemoteIP)(nil)
_ RequestMatcher = (*MatchNegate)(nil) _ RequestMatcher = (*MatchNot)(nil)
_ caddy.Provisioner = (*MatchNegate)(nil) _ caddy.Provisioner = (*MatchNot)(nil)
_ caddy.Provisioner = (*MatchRegexp)(nil) _ caddy.Provisioner = (*MatchRegexp)(nil)
_ caddyfile.Unmarshaler = (*MatchHost)(nil) _ caddyfile.Unmarshaler = (*MatchHost)(nil)
@ -865,6 +865,6 @@ var (
_ caddyfile.Unmarshaler = (*MatchProtocol)(nil) _ caddyfile.Unmarshaler = (*MatchProtocol)(nil)
_ caddyfile.Unmarshaler = (*MatchRemoteIP)(nil) _ caddyfile.Unmarshaler = (*MatchRemoteIP)(nil)
_ json.Marshaler = (*MatchNegate)(nil) _ json.Marshaler = (*MatchNot)(nil)
_ json.Unmarshaler = (*MatchNegate)(nil) _ json.Unmarshaler = (*MatchNot)(nil)
) )

View File

@ -127,7 +127,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
"file": h.JSON(fileserver.MatchFile{ "file": h.JSON(fileserver.MatchFile{
TryFiles: []string{"{http.request.uri.path}/index.php"}, TryFiles: []string{"{http.request.uri.path}/index.php"},
}), }),
"not": h.JSON(caddyhttp.MatchNegate{ "not": h.JSON(caddyhttp.MatchNot{
MatchersRaw: caddy.ModuleMap{ MatchersRaw: caddy.ModuleMap{
"path": h.JSON(caddyhttp.MatchPath{"*/"}), "path": h.JSON(caddyhttp.MatchPath{"*/"}),
}, },