json

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeJSON

func EncodeJSON(w io.Writer, v any) error

A wrapper for json data encoding.

func ParseJSON

func ParseJSON[T any](r io.Reader) (T, error)

Same as func ParseJSONInto, but initziliazes new var of T.

func ParseJSONInto

func ParseJSONInto[T any](r io.Reader, target *T) error

Can be called when already having a var of type T. Unmarshals data into the target.

func SendErrorJSON

func SendErrorJSON(w http.ResponseWriter, status int, msg string) error

Sends structured json error. As marshal can fail, it returns error.

func WriteJSON

func WriteJSON(w http.ResponseWriter, s int, v any) error

A func that can be used in handlers to write JSON. Includes status code and structured data to marshall.

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"` // Error message with json tag
}

Simple error response struct with json notation.

Jump to

Keyboard shortcuts

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