json

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2025 License: GPL-3.0 Imports: 5 Imported by: 1

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

func (e Encoder) Encode(
	body any,
) ([]byte, error)

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

func (e Encoder) EncodeAndWrite(
	writer io.Writer,
	beforeWriteFn func() error,
	body any,
) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL