api

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 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(store *sessions.Store) 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(s *sessions.Store, r *http.Request, v interface{})

func LoadBearer

func LoadBearer(s *sessions.Store, r *http.Request, v interface{})

func LoadHeadless

func LoadHeadless(s *sessions.Store, r *http.Request, v interface{})

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 422 if the value fails ozzo validation and 400 due to 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