MCPcopy
hub / github.com/caddyserver/caddy / ParseStructTag

Function ParseStructTag

modules.go:322–336  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

320// It is very simple. The expected syntax is:
321// `caddy:"key1=val1 key2=val2 ..."`
322func 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

Callers 1

LoadModuleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected