echo – github.com/labstack/echo Index | Files | Directories

package echo

import "github.com/labstack/echo"

Index

Constants

const (
	// CONNECT HTTP method
	CONNECT = "CONNECT"
	// DELETE HTTP method
	DELETE = "DELETE"
	// GET HTTP method
	GET = "GET"
	// HEAD HTTP method
	HEAD = "HEAD"
	// OPTIONS HTTP method
	OPTIONS = "OPTIONS"
	// PATCH HTTP method
	PATCH = "PATCH"
	// POST HTTP method
	POST = "POST"
	// PUT HTTP method
	PUT = "PUT"
	// TRACE HTTP method
	TRACE = "TRACE"

	ApplicationJSON     = "application/json; charset=utf-8"
	ApplicationXML      = "application/xml; charset=utf-8"
	ApplicationForm     = "application/x-www-form-urlencoded"
	ApplicationProtobuf = "application/protobuf"
	ApplicationMsgpack  = "application/msgpack"
	TextHTML            = "text/html; charset=utf-8"
	TextPlain           = "text/plain; charset=utf-8"
	MultipartForm       = "multipart/form-data"

	Accept             = "Accept"
	AcceptEncoding     = "Accept-Encoding"
	Authorization      = "Authorization"
	ContentDisposition = "Content-Disposition"
	ContentEncoding    = "Content-Encoding"
	ContentLength      = "Content-Length"
	ContentType        = "Content-Type"
	Location           = "Location"
	Upgrade            = "Upgrade"
	Vary               = "Vary"

	WebSocket = "websocket"
)

Variables

var (
	UnsupportedMediaType  = errors.New("echo ⇒ unsupported media type")
	RendererNotRegistered = errors.New("echo ⇒ renderer not registered")
)

Types

type BindFunc

type BindFunc func(*http.Request, interface{}) error

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context represents context for the current request. It holds request and response objects, path parameters, data and registered handler.

func NewContext

func NewContext(req *http.Request, res *Response, e *Echo) *Context

NewContext creates a Context object.

func (*Context) Bind

func (c *Context) Bind(i interface{}) error

Bind binds the request body into specified type v. Default binder does it based on Content-Type header.

func (*Context) Error

func (c *Context) Error(err error)

Error invokes the registered HTTP error handler. Generally used by middleware.

func (*Context) Form

func (c *Context) Form(name string) string

Form returns form parameter by name.

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get retrieves data from the context.

func (*Context) HTML

func (c *Context) HTML(code int, format string, a ...interface{}) (err error)

HTML formats according to a format specifier and sends text/html response with status code.

func (*Context) JSON

func (c *Context) JSON(code int, i interface{}) (err error)

JSON sends an application/json response with status code.

func (*Context) NoContent

func (c *Context) NoContent(code int) error

NoContent sends a response with no body and a status code.

func (*Context) P

func (c *Context) P(i int) (value string)

P returns path parameter by index.

func (*Context) Param

func (c *Context) Param(name string) (value string)

Param returns path parameter by name.

func (*Context) Query

func (c *Context) Query(name string) string

Query returns query parameter by name.

func (*Context) Redirect

func (c *Context) Redirect(code int, url string) error

Redirect redirects the request using http.Redirect with status code.

func (*Context) Render

func (c *Context) Render(code int, name string, data interface{}) (err error)

Render renders a template with data and sends a text/html response with status code. Templates can be registered using `Echo.SetRenderer()`.

func (*Context) Request

func (c *Context) Request() *http.Request

Request returns *http.Request.

func (*Context) Response

func (c *Context) Response() *Response

Response returns *Response.

func (*Context) Set

func (c *Context) Set(key string, val interface{})

Set saves data in the context.

func (*Context) Socket

func (c *Context) Socket() *websocket.Conn

Socket returns *websocket.Conn.

func (*Context) String

func (c *Context) String(code int, format string, a ...interface{}) (err error)

String formats according to a format specifier and sends text/plain response with status code.

func (*Context) XML

func (c *Context) XML(code int, i interface{}) (err error)

XML sends an application/xml response with status code.

type Echo

type Echo struct {
	// contains filtered or unexported fields
}

func New

func New() (e *Echo)

New creates an instance of Echo.

func (*Echo) ColoredLog

func (e *Echo) ColoredLog(on bool)

ColoredLog enable/disable colored log.

func (*Echo) Connect

func (e *Echo) Connect(path string, h Handler)

Connect adds a CONNECT route > handler to the router.

func (*Echo) Debug

func (e *Echo) Debug() bool

Debug returns debug mode.

func (*Echo) DefaultHTTPErrorHandler

func (e *Echo) DefaultHTTPErrorHandler(err error, c *Context)

DefaultHTTPErrorHandler invokes the default HTTP error handler.

func (*Echo) Delete

func (e *Echo) Delete(path string, h Handler)

Delete adds a DELETE route > handler to the router.

func (*Echo) Favicon

func (e *Echo) Favicon(file string)

Favicon serves the default favicon - GET /favicon.ico.

func (*Echo) Get

func (e *Echo) Get(path string, h Handler)

Get adds a GET route > handler to the router.

func (*Echo) Group

func (e *Echo) Group(prefix string, m ...Middleware) *Group

Group creates a new sub router with prefix. It inherits all properties from the parent. Passing middleware overrides parent middleware.

func (*Echo) HTTP2

func (e *Echo) HTTP2(on bool)

HTTP2 enable/disable HTTP2 support.

func (*Echo) Head

func (e *Echo) Head(path string, h Handler)

Head adds a HEAD route > handler to the router.

func (*Echo) Index

func (e *Echo) Index(file string)

Index serves index file.

func (*Echo) Options

func (e *Echo) Options(path string, h Handler)

Options adds an OPTIONS route > handler to the router.

func (*Echo) Patch

func (e *Echo) Patch(path string, h Handler)

Patch adds a PATCH route > handler to the router.

func (*Echo) Post

func (e *Echo) Post(path string, h Handler)

Post adds a POST route > handler to the router.

func (*Echo) Put

func (e *Echo) Put(path string, h Handler)

Put adds a PUT route > handler to the router.

func (*Echo) Router

func (e *Echo) Router() *Router

Router returns router.

func (*Echo) Routes

func (e *Echo) Routes() []Route

Routes returns the registered routes.

func (*Echo) Run

func (e *Echo) Run(addr string)

Run runs a server.

func (*Echo) RunServer

func (e *Echo) RunServer(s *http.Server)

RunServer runs a custom server.

func (*Echo) RunTLS

func (e *Echo) RunTLS(addr, certFile, keyFile string)

RunTLS runs a server with TLS configuration.

func (*Echo) RunTLSServer

func (e *Echo) RunTLSServer(s *http.Server, certFile, keyFile string)

RunTLSServer runs a custom server with TLS configuration.

func (*Echo) ServeDir

func (e *Echo) ServeDir(path, dir string)

ServeDir serves files from a directory.

func (*Echo) ServeFile

func (e *Echo) ServeFile(path, file string)

ServeFile serves a file.

func (*Echo) ServeHTTP

func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements `http.Handler` interface, which serves HTTP requests.

func (*Echo) Server

func (e *Echo) Server(addr string) *http.Server

Server returns the internal *http.Server.

func (*Echo) SetBinder

func (e *Echo) SetBinder(b BindFunc)

SetBinder registers a custom binder. It's invoked by Context.Bind().

func (*Echo) SetDebug

func (e *Echo) SetDebug(on bool)

SetDebug sets debug mode.

func (*Echo) SetHTTPErrorHandler

func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)

SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.

func (*Echo) SetRenderer

func (e *Echo) SetRenderer(r Renderer)

SetRenderer registers an HTML template renderer. It's invoked by Context.Render().

func (*Echo) Static

func (e *Echo) Static(path, dir string)

Static serves static files from a directory. It's an alias for `Echo.ServeDir`

func (*Echo) Trace

func (e *Echo) Trace(path string, h Handler)

Trace adds a TRACE route > handler to the router.

func (*Echo) URI

func (e *Echo) URI(h Handler, params ...interface{}) string

URI generates a URI from handler.

func (*Echo) URL

func (e *Echo) URL(h Handler, params ...interface{}) string

URL is an alias for `URI` function.

func (*Echo) Use

func (e *Echo) Use(m ...Middleware)

Use adds handler to the middleware chain.

func (*Echo) WebSocket

func (e *Echo) WebSocket(path string, h HandlerFunc)

WebSocket adds a WebSocket route > handler to the router.

type Group

type Group struct {
	// contains filtered or unexported fields
}

func (*Group) Connect

func (g *Group) Connect(path string, h Handler)

func (*Group) Delete

func (g *Group) Delete(path string, h Handler)

func (*Group) Get

func (g *Group) Get(path string, h Handler)

func (*Group) Group

func (g *Group) Group(prefix string, m ...Middleware) *Group

func (*Group) Head

func (g *Group) Head(path string, h Handler)

func (*Group) Options

func (g *Group) Options(path string, h Handler)

func (*Group) Patch

func (g *Group) Patch(path string, h Handler)

func (*Group) Post

func (g *Group) Post(path string, h Handler)

func (*Group) Put

func (g *Group) Put(path string, h Handler)

func (*Group) ServeDir

func (g *Group) ServeDir(path, root string)

func (*Group) ServeFile

func (g *Group) ServeFile(path, file string)

func (*Group) Static

func (g *Group) Static(path, root string)

func (*Group) Trace

func (g *Group) Trace(path string, h Handler)

func (*Group) Use

func (g *Group) Use(m ...Middleware)

func (*Group) WebSocket

func (g *Group) WebSocket(path string, h HandlerFunc)

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

func NewHTTPError

func NewHTTPError(code int, msg ...string) *HTTPError

func (*HTTPError) Code

func (e *HTTPError) Code() int

Code returns code.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns message.

func (*HTTPError) SetCode

func (e *HTTPError) SetCode(code int)

SetCode sets code.

type HTTPErrorHandler

type HTTPErrorHandler func(error, *Context)

HTTPErrorHandler is a centralized HTTP error handler.

type Handler

type Handler interface{}

type HandlerFunc

type HandlerFunc func(*Context) error

type Middleware

type Middleware interface{}

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

type Renderer

type Renderer interface {
	Render(w io.Writer, name string, data interface{}) error
}

Renderer is the interface that wraps the Render method.

Render renders the HTML template with given name and specified data. It writes the output to w.

type Response

type Response struct {
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) CloseNotify

func (r *Response) CloseNotify() <-chan bool

CloseNotify wraps response writer's CloseNotify function.

func (*Response) Flush

func (r *Response) Flush()

Flush wraps response writer's Flush function.

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack wraps response writer's Hijack function.

func (*Response) SetWriter

func (r *Response) SetWriter(w http.ResponseWriter)

func (*Response) Size

func (r *Response) Size() int64

func (*Response) Status

func (r *Response) Status() int

func (*Response) Write

func (r *Response) Write(b []byte) (n int, err error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

func (*Response) Writer

func (r *Response) Writer() http.ResponseWriter

type Route

type Route struct {
	Method  string
	Path    string
	Handler Handler
}

type Router

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

func NewRouter

func NewRouter(e *Echo) (r *Router)

func (*Router) Add

func (r *Router) Add(method, path string, h HandlerFunc, e *Echo)

func (*Router) Find

func (r *Router) Find(method, path string, ctx *Context) (h HandlerFunc, e *Echo)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

Source Files

context.go echo.go group.go response.go router.go

Directories

PathSynopsis
examples
examples/crud
examples/hello
examples/middleware
examples/website
middleware
recipes
recipes/file-upload
recipes/graceful-shutdown
recipes/graceful-shutdown/grace
recipes/graceful-shutdown/graceful
recipes/jwt-authentication
recipes/jwt-authentication/token
recipes/streaming-file-upload
recipes/streaming-response
recipes/subdomains
recipes/websocket
Version
v1.1.0
Published
Jul 18, 2015
Platform
windows/amd64
Imports
19 packages
Last checked
1 week ago

Tools for package owners.