ecchi

package module
v0.0.0-...-635372c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: MIT Imports: 3 Imported by: 0

README

Ecchi for Go

Q. What is this? A. This is a "extension" of the errchi project by diamondburned. Since it no longer deals with just errors, I decided to name it eChi at first, short for extended chi, until I managed to come up with this pun. Major features involve auto JSON marshaling.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(h Handler) http.HandlerFunc

Wrap converts a ecchi handler into http handler.

Types

type Ctx

type Ctx struct {
	W http.ResponseWriter
	R *http.Request
}

Ctx is the context for ecchi

func (*Ctx) Code

func (c *Ctx) Code(code int) *Ctx

Code sets the status code. Defaults to 200.

func (*Ctx) ErrorJSON

func (c *Ctx) ErrorJSON(r *RestError) *Ctx

ErrorJSON returns a JSON, as error.

func (*Ctx) JSON

func (c *Ctx) JSON(v interface{}) *Ctx

JSON writes a JSON response.

func (*Ctx) ReadJSON

func (c *Ctx) ReadJSON(dst interface{}) error

ReadJSON reads JSON Payload

func (*Ctx) ServerError

func (c *Ctx) ServerError(e error) *Ctx

ServerError is for unexpected server errors.

type Handler

type Handler func(*Ctx) *Ctx

Handler is the handler function

type RestError

type RestError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Code    int    `json:"code"`
}

RestError is an error for REST endpoints.

type Router

type Router struct {
	chi.Router
}

Router routes ecchi

func NewRouter

func NewRouter() *Router

NewRouter creates an ecchi router.

func (*Router) Connect

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

Connect is a wrapper method.

func (*Router) Delete

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

Delete is a wrapper method.

func (*Router) Get

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

Get is a wrapper method.

func (*Router) Head

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

Head is a wrapper method.

func (*Router) Options

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

Options is a wrapper method.

func (*Router) Patch

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

Patch is a wrapper method.

func (*Router) Post

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

Post is a wrapper method.

func (*Router) Put

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

Put is a wrapper method.

func (*Router) Trace

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

Trace is a wrapper method.

Jump to

Keyboard shortcuts

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