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

Method UnmarshalJSON

modules/caddyhttp/caddyhttp.go:166–184  ·  view source on GitHub ↗

UnmarshalJSON satisfies json.Unmarshaler according to this type's documentation.

(b []byte)

Source from the content-addressed store, hash-verified

164// UnmarshalJSON satisfies json.Unmarshaler according to
165// this type's documentation.
166func (ws *WeakString) UnmarshalJSON(b []byte) error {
167 if len(b) == 0 {
168 return io.EOF
169 }
170 if b[0] == byte('"') && b[len(b)-1] == byte('"') {
171 var s string
172 err := json.Unmarshal(b, &s)
173 if err != nil {
174 return err
175 }
176 *ws = WeakString(s)
177 return nil
178 }
179 if bytes.Equal(b, []byte("null")) {
180 return nil
181 }
182 *ws = WeakString(b)
183 return nil
184}
185
186// MarshalJSON marshals was a boolean if true or false,
187// a number if an integer, or a string otherwise.

Callers

nothing calls this directly

Calls 2

WeakStringTypeAlias · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected