httpjson

package
v4.76.4 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 8 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotMarshal = errors.New("cannot marshal json")
)

Functions

func Parse added in v4.8.0

func Parse(req *http.Request, obj any) error

func RawWrite added in v4.22.0

func RawWrite(w io.Writer, obj any) error

func Read added in v4.5.0

func Read(resp *http.Response, obj any) error

func Stream added in v4.9.0

func Stream[T any](reader io.Reader, output chan<- T, key string, closeChan bool) error

Stream decodes JSON from a `reader` and send unmarshalled `T` to the given `output` chan `closeChan` make Stream to close the `output` channel once read. There is no guarantee that the `reader` wil be fully read. For HTTP Body you might want to drain it.

`key` supports three kinds of values: - "" => the reader contains a stream of objects like `{"id":12}{"id":34}{"id":56}`, e.g. processing a websocket - "." => the reader contains an array of objects like `[{"id":12},{"id":34},{"id":56}]` - <key name>" => the reader contains an array of objects at the given root key `{"items":[{"id":12},{"id":34},{"id":56}]}`.

func Write added in v4.5.0

func Write(ctx context.Context, w http.ResponseWriter, status int, obj any)

func WriteArray added in v4.5.0

func WriteArray(ctx context.Context, w http.ResponseWriter, status int, array any)

Types

This section is empty.

Jump to

Keyboard shortcuts

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