json

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeJSONMarshalFailed string
)

Functions

This section is empty.

Types

type Encoder added in v0.11.2

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder struct

func NewEncoder added in v0.11.2

func NewEncoder(
	modeFlag *mode.Flag,
) *Encoder

NewEncoder creates a new default JSON encoder

Parameters:

  • modeFlag: The flag mode

Returns:

  • *Encoder: The default encoder

func (Encoder) Encode added in v0.11.2

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 added in v0.12.3

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

func (Encoder) EncodeAndWriteResponse added in v0.12.3

func (e Encoder) EncodeAndWriteResponse(
	writer http.ResponseWriter,
	response gonethttpresponse.Response,
) error

EncodeAndWriteResponse encodes the response and writes it to the http.ResponseWriter

Parameters:

  • writer: The http.ResponseWriter
  • response: The response to encode and write

Returns:

  • error: The error if any

func (Encoder) EncodeResponse added in v0.12.3

func (e Encoder) EncodeResponse(
	response gonethttpresponse.Response,
) ([]byte, error)

EncodeResponse encodes the response into JSON bytes

Parameters:

  • response: The response to encode

Returns:

  • []byte: The encoded JSON bytes
  • error: The error if any

type StreamEncoder added in v0.11.2

type StreamEncoder struct {
	// contains filtered or unexported fields
}

StreamEncoder is the JSON encoder struct

func NewStreamEncoder added in v0.11.2

func NewStreamEncoder(
	mode *goflagsmode.Flag,
	logger *slog.Logger,
) *StreamEncoder

NewStreamEncoder creates a new JSON encoder

Parameters:

  • mode: The flag mode
  • logger: The logger

Returns:

  • *StreamEncoder: The default encoder

func (StreamEncoder) Encode added in v0.11.2

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 added in v0.12.3

func (s StreamEncoder) EncodeAndWrite(
	writer io.Writer,
	beforeWriteFn func() error,
	body any,
) 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

func (StreamEncoder) EncodeAndWriteResponse added in v0.12.3

func (s StreamEncoder) EncodeAndWriteResponse(
	writer http.ResponseWriter,
	response gonethttpresponse.Response,
) error

EncodeAndWriteResponse encodes the body into JSON and writes it to the response

Parameters:

  • writer: The HTTP response writer
  • response: The response to encode

Returns:

  • error: The error if any

func (StreamEncoder) EncodeResponse added in v0.12.3

func (s StreamEncoder) EncodeResponse(
	response gonethttpresponse.Response,
) ([]byte, error)

EncodeResponse encodes the body into JSON

Parameters:

  • response: The response to encode

Returns:

  • ([]byte): The encoded JSON
  • error: The error if any

Jump to

Keyboard shortcuts

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