Documentation
¶
Overview ¶
Package response_writer provides legacy JSON response helpers retained for v2 source compatibility.
New code should prefer github.com/aatuh/api-toolkit/v2/httpx for JSON success responses, Problem Details errors, response capture, and response wrapper behavior. This package is stable for v2 callers but compatibility-sensitive and not a template for new response helper design.
Index ¶
- func WriteErr(w http.ResponseWriter, code int, msg string)
- func WriteJSON(w http.ResponseWriter, code int, v any)
- type Capture
- func (c *Capture) Body() []byte
- func (c *Capture) BytesWritten() int
- func (c *Capture) Header() http.Header
- func (c *Capture) Overflowed() bool
- func (c *Capture) Status() int
- func (c *Capture) Write(b []byte) (int, error)
- func (c *Capture) WriteHeader(code int)
- func (c *Capture) WriteTo(w http.ResponseWriter)
- type Writer
- func (w *Writer) BytesWritten() int
- func (w *Writer) Committed() bool
- func (w *Writer) Flush()
- func (w *Writer) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *Writer) Push(target string, opts *http.PushOptions) error
- func (w *Writer) ReadFrom(r io.Reader) (int64, error)
- func (w *Writer) Status() int
- func (w *Writer) Unwrap() http.ResponseWriter
- func (w *Writer) Write(b []byte) (int, error)
- func (w *Writer) WriteHeader(code int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Capture ¶
type Capture struct {
// contains filtered or unexported fields
}
Capture buffers response headers and body for later replay. It intentionally does not preserve optional http.ResponseWriter interfaces such as Flusher, Hijacker, Pusher, or ReaderFrom.
func NewLimitedCapture ¶ added in v2.1.0
NewLimitedCapture creates a buffered response writer with a maximum stored body size.
func (*Capture) BytesWritten ¶
BytesWritten returns the number of buffered bytes.
func (*Capture) Overflowed ¶ added in v2.1.0
Overflowed reports whether buffered writes exceeded the configured maximum body size.
func (*Capture) WriteHeader ¶
WriteHeader records the status code without writing.
func (*Capture) WriteTo ¶
func (c *Capture) WriteTo(w http.ResponseWriter)
WriteTo writes the buffered response to the provided ResponseWriter.
type Writer ¶
type Writer struct {
http.ResponseWriter
// contains filtered or unexported fields
}
Writer wraps an http.ResponseWriter and tracks status/bytes. It forwards optional interfaces (Flusher, Hijacker, Pusher, ReaderFrom).
func Wrap ¶
func Wrap(w http.ResponseWriter) *Writer
Wrap returns a response writer wrapper that tracks status and bytes.
func (*Writer) BytesWritten ¶
BytesWritten returns the number of bytes written.
func (*Writer) Committed ¶ added in v2.1.0
Committed reports whether headers or body bytes have been written.
func (*Writer) Push ¶
func (w *Writer) Push(target string, opts *http.PushOptions) error
Push forwards server push if supported.
func (*Writer) Unwrap ¶
func (w *Writer) Unwrap() http.ResponseWriter
Unwrap returns the underlying http.ResponseWriter.
func (*Writer) WriteHeader ¶
WriteHeader captures the status code and forwards to the underlying writer.