api

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var STACK_SIZE = 12 * 1024

STACK_SIZE is the number of bytes to print to stderr when recovering from a panic

View Source
var StringParam = requests.StringParam

StringParam basically just ensures the param name is correct. You might not need this method unless you're too lazy to do real tests. Panics if there's no param with the name.

Functions

func Error

func Error(r *http.Request, w http.ResponseWriter, err Err)

Error sends a JSend error message. It logs the response if a zerolog.Logger is attached to the request.

func Headless

func Headless(manager *sessions.Manager) func(http.Handler) http.Handler

func IDParam

func IDParam(r *http.Request, name string) uint

IDParam extracts a uint URL parameter from the given request. panics with a 400 if the param is not a strin, otherwise it panics with a basic error.

func Load

func Load(m *sessions.Manager, r *http.Request, v interface{})

func LoadBearer

func LoadBearer(m *sessions.Manager, r *http.Request, v interface{})

func LoadCookie added in v0.19.0

func LoadCookie(m *sessions.Manager, r *http.Request, v interface{})

func LoadHeadless

func LoadHeadless(m *sessions.Manager, r *http.Request, v interface{})

func QueryParam added in v0.17.0

func QueryParam(r *http.Request, v interface{})

QueryParams converts the query values of the request into a struct using the "json" tag to map the keys. It supports transformations using modl and validation provided by ozzo. It panics with a 400 if the value fails ozzo validation or any other error

func ReadJSON

func ReadJSON(r *http.Request, v interface{})

ReadJSON parses the body of an http request into the value pointed by v. It panics with a 415 error if the content type is not JSON, a 400 if the value fails ozzo validation or any other error(JSON decode error for instance)

func Recoverer

func Recoverer(env string) func(http.Handler) http.Handler

Recoverer creates a middleware that handles panics from chi controllers. It handles printing(optionally stack trace in dev env) and responding to the client for all errors except Err.

Note that all errors(bar Err and request context timeouts) respond with a 500

func Success

func Success(r *http.Request, w http.ResponseWriter, v interface{})

Success sends a JSend success message with status code 200. It logs the response if a zerolog.Logger is attached to the request.

Types

type Err

type Err struct {
	Code    int         `json:"-"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Err     error       `json:"-"`
}

Err defines the structure of an HTTP error response

func (Err) Error

func (e Err) Error() string

func (Err) Unwrap

func (e Err) Unwrap() error

Jump to

Keyboard shortcuts

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