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

Function JSON

caddyconfig/configadapters.go:51–60  ·  view source on GitHub ↗

JSON encodes val as JSON, returning it as a json.RawMessage. Any marshaling errors (which are highly unlikely with correct code) are converted to warnings. This is convenient when filling config structs that require a json.RawMessage, without having to worry about errors.

(val any, warnings *[]Warning)

Source from the content-addressed store, hash-verified

49// structs that require a json.RawMessage, without having to worry
50// about errors.
51func JSON(val any, warnings *[]Warning) json.RawMessage {
52 b, err := json.Marshal(val)
53 if err != nil {
54 if warnings != nil {
55 *warnings = append(*warnings, Warning{Message: err.Error()})
56 }
57 return nil
58 }
59 return b
60}
61
62// JSONModuleObject is like JSON(), except it marshals val into a JSON object
63// with an added key named fieldName with the value fieldVal. This is useful

Callers 15

cmdRespondFunction · 0.92
UnmarshalCaddyfileMethod · 0.92
parseCaddyfileFunction · 0.92
cmdReverseProxyFunction · 0.92
parseCaddyfileFunction · 0.92
UnmarshalCaddyfileMethod · 0.92
cmdFileServerFunction · 0.92
parseAppFunction · 0.92
SetupMethod · 0.92
serversFromPairingsMethod · 0.92
parseMatcherDefinitionsFunction · 0.92

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected