ParseStructTag parses a caddy struct tag into its keys and values. It is very simple. The expected syntax is: `caddy:"key1=val1 key2=val2 ..."`
(tag string)
| 320 | // It is very simple. The expected syntax is: |
| 321 | // `caddy:"key1=val1 key2=val2 ..."` |
| 322 | func ParseStructTag(tag string) (map[string]string, error) { |
| 323 | results := make(map[string]string) |
| 324 | pairs := strings.Split(tag, " ") |
| 325 | for i, pair := range pairs { |
| 326 | if pair == "" { |
| 327 | continue |
| 328 | } |
| 329 | before, after, isCut := strings.Cut(pair, "=") |
| 330 | if !isCut { |
| 331 | return nil, fmt.Errorf("missing key in '%s' (pair %d)", pair, i) |
| 332 | } |
| 333 | results[before] = after |
| 334 | } |
| 335 | return results, nil |
| 336 | } |
| 337 | |
| 338 | // StrictUnmarshalJSON is like json.Unmarshal but returns an error |
| 339 | // if any of the fields are unrecognized. Useful when decoding |