rest

package
v0.0.0-...-19f3120 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserInfo

func GetUserInfo(r *http.Request) (user store.User, err error)

GetUserInfo returns user from request context

func GetUserOrEmpty

func GetUserOrEmpty(r *http.Request) store.User

GetUserOrEmpty attempts to get user info from request and returns empty object if failed

func MustGetUserInfo

func MustGetUserInfo(r *http.Request) store.User

MustGetUserInfo fails if can't extract user data from the request. should be called from authed controllers only

func SendErrorJSON

func SendErrorJSON(w http.ResponseWriter, r *http.Request, httpStatusCode int, err error, errMsg string, errCode ErrCode)

SendErrorJSON makes {error: blah, details: blah} json body and responds with error code

func SetUserInfo

func SetUserInfo(r *http.Request, user store.User) *http.Request

SetUserInfo sets user into request context

Types

type ErrCode

type ErrCode int

ErrCode is used for client mapping and translation

const (
	ErrInternal   ErrCode = 0 // any internal error
	ErrDecode     ErrCode = 1 // failed to unmarshal incoming request
	ErrBadRequest ErrCode = 2 // request contains incorrect data or doesn't contain data
)

All error codes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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