api

package module
v0.0.0-...-8f030ab Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	RequestErrAccessDenied  = "access_denied"
	RequestErrInsufficient  = "insufficient"
	RequestErrOverflow      = "overflow"
	RequestErrInvalidValue  = "invalid_value"
	RequestErrInvalidFormat = "invalid_format"
	RequestErrMissing       = "missing"
	RequestErrNotFound      = "not_found"
	RequestErrConflict      = "conflict"
	RequestErrActOfGod      = "act_of_god"
)

Variables

View Source
var (
	ActOfGodError      = []RequestError{{Slug: RequestErrActOfGod}}
	InvalidFormatError = []RequestError{{Slug: RequestErrInvalidFormat, Field: "/"}}
	AccessDeniedError  = []RequestError{{Slug: RequestErrAccessDenied}}

	Encoders = []string{"application/json"}

	ErrUserIDNotSet = errors.New("user ID not set")
	ErrInvalidUUID  = errors.New("not a valid uuid")
)

Functions

func ActOfGodDef

func ActOfGodDef(r *http.Response, err RequestError) bool

func AuthUser

func AuthUser(r *http.Request) (uuid.UUID, error)

func CORSMiddleware

func CORSMiddleware(h http.Handler) http.Handler

func CheckScopes

func CheckScopes(scopes []string, checking ...string) bool

func ContextWrapper

func ContextWrapper(c context.Context, handler ContextHandler) http.Handler

func Decode

func Decode(r *http.Request, target interface{}) error

func DecodeErrors

func DecodeErrors(r *http.Response, errs []RequestError, defs []ErrorDef) []error

func Encode

func Encode(w http.ResponseWriter, r *http.Request, status int, resp interface{})

func ErrDefCodeParamSlug

func ErrDefCodeParamSlug(code int, param, slug string) func(*http.Response, RequestError) bool

func ErrorDefCodeFieldSlug

func ErrorDefCodeFieldSlug(code int, field, slug string) func(*http.Response, RequestError) bool

func GetScopes

func GetScopes(r *http.Request) []string

func InvalidFormatDef

func InvalidFormatDef(r *http.Response, err RequestError) bool

func NegotiateMiddleware

func NegotiateMiddleware(h http.Handler) http.Handler

func ParamInvalidFormatDef

func ParamInvalidFormatDef(param string) func(*http.Response, RequestError) bool

func ParamInvalidValueDef

func ParamInvalidValueDef(param string) func(*http.Response, RequestError) bool

func ParamNotFoundDef

func ParamNotFoundDef(param string) func(*http.Response, RequestError) bool

Types

type ContextHandler

type ContextHandler func(context.Context, http.ResponseWriter, *http.Request)

type ErrorDef

type ErrorDef struct {
	Test func(*http.Response, RequestError) bool
	Err  error
}

type RequestError

type RequestError struct {
	Slug   string `json:"error,omitempty"`
	Field  string `json:"field,omitempty"`
	Param  string `json:"param,omitempty"`
	Header string `json:"header,omitempty"`
}

type UnhandledRequestError

type UnhandledRequestError RequestError

func (UnhandledRequestError) Error

func (u UnhandledRequestError) Error() string

func (UnhandledRequestError) RequestError

func (u UnhandledRequestError) RequestError() RequestError

Jump to

Keyboard shortcuts

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