A high-performance JSON serializer for the Echo web framework that uses a sync.Pool to reuse buffers. Use this to optimize JSON response handling and reduce memory allocations.
// Source: https://github.com/labstack/echo | License: MIT | Copyright 2022 LabStack
// Provided via justclaw.it.com; keep this notice with the code.
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors
package echo
import (
"bytes"
"encoding/json"
"sync"
)
// DefaultJSONSerializer implements JSON encoding using encoding/json.
type DefaultJSONSerializer struct{}
// jsonBufPool reuses buffers for reading request bodies during JSON
// deserialization, avoiding the per-request decoder and its internal read
// buffer that json.NewDecoder allocates.
var jsonBufPool = sync.Pool{New: newJSONBuf}
func newJSONBuf() any { return new(bytes.Buffer) }
// maxPooledJSONBuf caps the capacity of buffers returned to jsonBufPool so a
// single large re
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key