MCPcopy Create free account
hub / github.com/caddyserver/caddy / UnmarshalJSON

Method UnmarshalJSON

modules/caddyhttp/logging.go:177–200  ·  view source on GitHub ↗

UnmarshalJSON satisfies json.Unmarshaler.

(b []byte)

Source from the content-addressed store, hash-verified

175
176// UnmarshalJSON satisfies json.Unmarshaler.
177func (sa *StringArray) UnmarshalJSON(b []byte) error {
178 var jsonObj any
179 err := json.Unmarshal(b, &jsonObj)
180 if err != nil {
181 return err
182 }
183 switch obj := jsonObj.(type) {
184 case string:
185 *sa = StringArray([]string{obj})
186 return nil
187 case []any:
188 s := make([]string, 0, len(obj))
189 for _, v := range obj {
190 value, ok := v.(string)
191 if !ok {
192 return errors.New("unsupported type")
193 }
194 s = append(s, value)
195 }
196 *sa = StringArray(s)
197 return nil
198 }
199 return errors.New("unsupported type")
200}
201
202// errLogValues inspects err and returns the status code
203// to use, the error log message, and any extra fields.

Callers

nothing calls this directly

Calls 1

StringArrayTypeAlias · 0.85

Tested by

no test coverage detected