ParseCaddyfileNestedMatcherSet parses the Caddyfile tokens for a nested matcher set, and returns its raw module map value.
(d *caddyfile.Dispenser)
| 1095 | // ParseCaddyfileNestedMatcherSet parses the Caddyfile tokens for a nested |
| 1096 | // matcher set, and returns its raw module map value. |
| 1097 | func ParseCaddyfileNestedMatcherSet(d *caddyfile.Dispenser) (caddy.ModuleMap, error) { |
| 1098 | matcherMap := make(map[string]ConnectionMatcher) |
| 1099 | |
| 1100 | tokensByMatcherName := make(map[string][]caddyfile.Token) |
| 1101 | for nesting := d.Nesting(); d.NextArg() || d.NextBlock(nesting); { |
| 1102 | matcherName := d.Val() |
| 1103 | tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegment()...) |
| 1104 | } |
| 1105 | |
| 1106 | for matcherName, tokens := range tokensByMatcherName { |
| 1107 | dd := caddyfile.NewDispenser(tokens) |
| 1108 | dd.Next() // consume wrapper name |
| 1109 | |
| 1110 | unm, err := caddyfile.UnmarshalModule(dd, "tls.handshake_match."+matcherName) |
| 1111 | if err != nil { |
| 1112 | return nil, err |
| 1113 | } |
| 1114 | cm, ok := unm.(ConnectionMatcher) |
| 1115 | if !ok { |
| 1116 | return nil, fmt.Errorf("matcher module '%s' is not a connection matcher", matcherName) |
| 1117 | } |
| 1118 | matcherMap[matcherName] = cm |
| 1119 | } |
| 1120 | |
| 1121 | matcherSet := make(caddy.ModuleMap) |
| 1122 | for name, matcher := range matcherMap { |
| 1123 | jsonBytes, err := json.Marshal(matcher) |
| 1124 | if err != nil { |
| 1125 | return nil, fmt.Errorf("marshaling %T matcher: %v", matcher, err) |
| 1126 | } |
| 1127 | matcherSet[name] = jsonBytes |
| 1128 | } |
| 1129 | |
| 1130 | return matcherSet, nil |
| 1131 | } |
no test coverage detected