handlertools

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFromQuery

func BoolFromQuery(r *http.Request, param string) (bool, error)

BoolFromQuery extracts a query string value and converts it to a bool

func DecodeJSON

func DecodeJSON(r *http.Request, data interface{}) error

DecodeJSON decodes a JSON request body into the provided data struct.

func EncodeJSON

func EncodeJSON(w http.ResponseWriter, data interface{}) error

EncodeJSON encodes data into JSON and writes it to the response writer.

func IntFromQuery

func IntFromQuery[T ~int | int32 | int64](
	r *http.Request,
	param string,
) (T, error)

IntFromQuery extracts a query string value and converts it to an int if it is not empty. If the value is empty, it returns 0.

func RenderError

func RenderError(w http.ResponseWriter, err error, status int)

RenderError renders an error response.

func UUIDFromURL

func UUIDFromURL(r *http.Request, w http.ResponseWriter, paramName string) uuid.UUID

UUIDFromURL parses a UUID from a Path parameter. If the UUID is invalid, an error is rendered and uuid.Nil is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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