ecchi

package module
v0.0.0-...-a5156fd Latest Latest
Warning

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

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

README

Ecchi

Getting started

go get -u github.com/thecactusblue/ecchi

Quick Start

r := ecchi.NewRouter()

type Message struct {
    Name    string
    Content string
}

r.Get("/echo", func(ctx *ecchi.Ctx) *ecchi.Ctx {
    var m Message
    ctx.ReadJSON(&m)

    return ctx.JSON(&Message{
        Name: "Echo",
        Content: m.Content,
    })
})

Q. What is this?

A. This is a "extension" of errchi 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 error) *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) URLParam

func (c *Ctx) URLParam(key string) string

URLParam gets URL param

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.

func NewError

func NewError(name string, code int, message string) *RestError

NewError creates a new error.

func (*RestError) Error

func (r *RestError) Error() string

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) Route

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

Route creates subroutes.

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