api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadJSON

func ReadJSON[T any](r *http.Request) (T, error)

ReadJSON reads the Request and returns the decoded payload as T. The request body needs to be closed by the caller

func WriteInternalError

func WriteInternalError(l *slog.Logger, w http.ResponseWriter, err error, msg string)

WriteInternalError handles generic server errors logging the error and writing the error response

func WriteJSON

func WriteJSON[T any](w http.ResponseWriter, status int, v T) error

WriteJSON encodes v as json and writes to the ResponseWriter setting the proper headers. It protects writing invalid json and returns an error instead.

Types

type TypeJSON

type TypeJSON int
const (
	TypeJSONObject TypeJSON = iota
	TypeJSONArray
	TypeJSONUnknown
	TypeJSONInvalid
)

func JSONType

func JSONType(payload []byte) TypeJSON

JSONType detects if the JSON payload is an array or an object

Jump to

Keyboard shortcuts

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