Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct{}
Encoder struct
func NewEncoder ¶
func NewEncoder() *Encoder
NewEncoder creates a new default JSON encoder
Returns:
- *Encoder: The default encoder
func (Encoder) Encode ¶
Encode encodes the body into JSON bytes
Parameters:
- body: The body to encode
Returns:
- []byte: The encoded JSON bytes
- error: The error if any
func (Encoder) EncodeAndWrite ¶
EncodeAndWrite encodes the body and writes it to the writer
Parameters:
- writer: The writer to write the response to - beforeWriteFn: The function to call before writing the response - body: The body to encode
Returns:
- error: The error if any
type StreamEncoder ¶
type StreamEncoder struct{}
StreamEncoder is the JSON encoder struct
func NewStreamEncoder ¶
func NewStreamEncoder() *StreamEncoder
NewStreamEncoder creates a new JSON encoder
Returns:
- *StreamEncoder: The default encoder
func (StreamEncoder) Encode ¶
func (s StreamEncoder) Encode( body any, ) ([]byte, error)
Encode encodes the body into JSON
Parameters:
- body: The body to encode
Returns:
- ([]byte): The encoded JSON
- error: The error if any
func (StreamEncoder) EncodeAndWrite ¶
func (s StreamEncoder) EncodeAndWrite( writer io.Writer, beforeWriteFn func() error, body any, ) (err error)
EncodeAndWrite encodes the body into JSON and writes it to the writer
Parameters:
- writer: The writer
- beforeWriteFn: The function to call before writing
- body: The body to encode
Returns:
- error: The error if any
Click to show internal directories.
Click to hide internal directories.