func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
	// first, unmarshal each matcher in the set from its tokens
	type matcherPair struct {
		raw     caddy.ModuleMap
		decoded MatcherSet
	}
	for d.Next() {
		var mp matcherPair
		matcherMap := make(map[string]RequestMatcher)

		// in case there are multiple instances of the same matcher, concatenate
		// their tokens (we expect that UnmarshalCaddyfile should be able to
		// handle more than one segment); otherwise, we'd overwrite other
		// instances of the matcher in this set
		tokensByMatcherName := make(map[string][]caddyfile.Token)
		for nesting := d.Nesting(); d.NextArg() || d.NextBlock(nesting); {
			matcherName := d.Val()
			tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegment()...)
		}
		for matcherName, tokens := range tokensByMatcherName {
			mod, err := caddy.GetModule("http.matchers." + matcherName)
			if err != nil {
				return d.Errf("getting matcher module '%s': %v", matcherName, err)
			}
			unm, ok := mod.New().(caddyfile.Unmarshaler)
			if !ok {
				return d.Errf("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
			}
			err = unm.UnmarshalCaddyfile(caddyfile.NewDispenser(tokens))
			if err != nil {
				return err
			}
			rm, ok := unm.(RequestMatcher)
			if !ok {
				return fmt.Errorf("matcher module '%s' is not a request matcher", matcherName)
			}
			matcherMap[matcherName] = rm
			mp.decoded = append(mp.decoded, rm)
		}

		// we should now have a functional 'not' matcher, but we also
		// need to be able to marshal as JSON, otherwise config
		// adaptation will be missing the matchers!
		mp.raw = make(caddy.ModuleMap)
		for name, matcher := range matcherMap {
			jsonBytes, err := json.Marshal(matcher)
			if err != nil {
				return fmt.Errorf("marshaling %T matcher: %v", matcher, err)
			}
			mp.raw[name] = jsonBytes
		}
		m.MatcherSetsRaw = append(m.MatcherSetsRaw, mp.raw)
	}
	return nil
}
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
// UnmarshalCaddyfile implements caddyfile . Unmarshaler .
func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
	type matcherPair struct {
		raw     caddy.ModuleMap
		decoded MatcherSet
	}
	for d.Next() {
		var mp matcherPair
		matcherMap := make(map[string]RequestMatcher)
		tokensByMatcherName := make(map[string][]caddyfile.Token)
		for nesting := d.Nesting(); d.NextArg() || d.NextBlock(nesting); {
			matcherName := d.Val()
			tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegment()...)
		}
		for matcherName, tokens := range tokensByMatcherName {
			mod, err := caddy.GetModule("http.matchers." + matcherName)
			if err != nil {
				return d.Errf("getting matcher module '%s': %v", matcherName, err)
			}
			unm, ok := mod.New().(caddyfile.Unmarshaler)
			if !ok {
				return d.Errf("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
			}
			err = unm.UnmarshalCaddyfile(caddyfile.NewDispenser(tokens))
			if err != nil {
				return err
			}
			rm, ok := unm.(RequestMatcher)
			if !ok {
				return fmt.Errorf("matcher module '%s' is not a request matcher", matcherName)
			}
			matcherMap[matcherName] = rm
			mp.decoded = append(mp.decoded, rm)
		}
		mp.raw = make(caddy.ModuleMap)
		for name, matcher := range matcherMap {
			jsonBytes, err := json.Marshal(matcher)
			if err != nil {
				return fmt.Errorf("marshaling %T matcher: %v", matcher, err)
			}
			mp.raw[name] = jsonBytes
		}
		m.MatcherSetsRaw = append(m.MatcherSetsRaw, mp.raw)
	}
	return nil
}
func ( m * MatchNot ) UnmarshalCaddyfile ( d * caddyfile . Dispenser ) error { type matcherPair struct { raw caddy . ModuleMap decoded MatcherSet } for d . Next ( ) { var mp matcherPair matcherMap := make ( map [ string ] RequestMatcher ) tokensByMatcherName := make ( map [ string ] [ ] caddyfile . Token ) for nesting := d . Nesting ( ) ; d . NextArg ( ) || d . NextBlock ( nesting ) ; { matcherName := d . Val ( ) tokensByMatcherName [ matcherName ] = append ( tokensByMatcherName [ matcherName ] , d . NextSegment ( ) ... ) } for matcherName , tokens := range tokensByMatcherName { mod , err := caddy . GetModule ( " " + matcherName ) if err != nil { return d . Errf ( " " , matcherName , err ) } unm , ok := mod . New ( ) . ( caddyfile . Unmarshaler ) if ! ok { return d . Errf ( " " , matcherName ) } err = unm . UnmarshalCaddyfile ( caddyfile . NewDispenser ( tokens ) ) if err != nil { return err } rm , ok := unm . ( RequestMatcher ) if ! ok { return fmt . Errorf ( " " , matcherName ) } matcherMap [ matcherName ] = rm mp . decoded = append ( mp . decoded , rm ) } mp . raw = make ( caddy . ModuleMap ) for name , matcher := range matcherMap { jsonBytes , err := json . Marshal ( matcher ) if err != nil { return fmt . Errorf ( " " , matcher , err ) } mp . raw [ name ] = jsonBytes } m . MatcherSetsRaw = append ( m . MatcherSetsRaw , mp . raw ) } return nil }
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
UnmarshalCaddyfile implements caddyfile . Unmarshaler .
// first, unmarshal each matcher in the set from its tokens // in case there are multiple instances of the same matcher, concatenate // their tokens (we expect that UnmarshalCaddyfile should be able to // handle more than one segment); otherwise, we'd overwrite other // instances of the matcher in this set // we should now have a functional 'not' matcher, but we also // need to be able to marshal as JSON, otherwise config // adaptation will be missing the matchers!