errchi

package module
v0.0.0-...-6bb6e90 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 3 Imported by: 4

README

errchi

go-chi with error handling stuff, very cool. also never fails.

Error JSON

{"error":"test error"}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorWriter = WriterJSON

Functions

func CraftJSON

func CraftJSON(err error) []byte

func Wrap

func Wrap(h Handler, mws ...MiddlewareFunc) http.HandlerFunc

func WriterJSON

func WriterJSON(w http.ResponseWriter, err error)

Types

type Error

type Error struct {
	Error string `json:"error"`
}

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) (int, error)
}

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) (int, error)

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

type Router

type Router struct {
	chi.Router
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Connect

func (r *Router) Connect(route string, hf HandlerFunc)

func (*Router) Delete

func (r *Router) Delete(route string, hf HandlerFunc)

func (*Router) Get

func (r *Router) Get(route string, hf HandlerFunc)

func (*Router) Handle

func (r *Router) Handle(route string, h Handler)

func (*Router) HandleFunc

func (r *Router) HandleFunc(route string, hf HandlerFunc)

func (*Router) Head

func (r *Router) Head(route string, hf HandlerFunc)

func (*Router) MethodFunc

func (r *Router) MethodFunc(method, route string, hf HandlerFunc)

func (*Router) Options

func (r *Router) Options(route string, hf HandlerFunc)

func (*Router) Patch

func (r *Router) Patch(route string, hf HandlerFunc)

func (*Router) Post

func (r *Router) Post(route string, hf HandlerFunc)

func (*Router) Put

func (r *Router) Put(route string, hf HandlerFunc)

func (*Router) Route

func (r *Router) Route(route string, c func(*Router))

Route mounts a sub-Router along a `route“ string.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(wr http.ResponseWriter, rq *http.Request)

func (*Router) Trace

func (r *Router) Trace(route string, hf HandlerFunc)

func (*Router) Use

func (r *Router) Use(ms ...MiddlewareFunc)

Use appends one or more middlewares onto the Router stack.

func (*Router) UseRegular

func (r *Router) UseRegular(ms ...func(http.Handler) http.Handler)

UseRegular appends regular HTTP middlewares into the underlying router.

func (*Router) With

func (r *Router) With(ms ...MiddlewareFunc) *Router

With adds inline middlewares for an endpoint handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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