MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / appendJSONMarshal

Method appendJSONMarshal

logger/formatter_json.go:198–220  ·  view source on GitHub ↗

appendJSONMarshal appends a JSON marshaled value to the buffer.

(val any)

Source from the content-addressed store, hash-verified

196
197// appendJSONMarshal appends a JSON marshaled value to the buffer.
198func (s *formatterJSON) appendJSONMarshal(val any) {
199 if err, ok := val.(error); ok && err != nil {
200 s.appendString(err.Error())
201 return
202 }
203
204 buf := newBuffer()
205 defer func() {
206 buf.free()
207 }()
208
209 enc := json.NewEncoder(buf)
210 enc.SetEscapeHTML(false)
211
212 if err := enc.Encode(val); err != nil {
213 // This should be a very unlikely situation, but just in case...
214 s.buf.appendStringRaw(`"<json marshal error>"`)
215 return
216 }
217
218 buf.removeNewline()
219 s.buf.append(*buf...)
220}
221
222// appendGroup appends a group of attributes to the buffer.
223func (s *formatterJSON) appendGroup(name string, attrs []slog.Attr) {

Callers 2

appendValueMethod · 0.95
appendStringMethod · 0.95

Calls 7

appendStringMethod · 0.95
freeMethod · 0.80
appendStringRawMethod · 0.80
removeNewlineMethod · 0.80
appendMethod · 0.80
newBufferFunction · 0.70
ErrorMethod · 0.65

Tested by

no test coverage detected