README ¶
NOTICE
- Master branch, website and godoc now points to Echo v2.
- Echo v2 is in beta but if you want to try it out here is the migrating [guide] (https://echo.labstack.com/guide/migrating)
- Looking for v1?
- Installation: Use a package manager (https://github.com/Masterminds/glide, it's nice!) to get stable v1 release/commit or use
go get gopkg.in/labstack/echo.v1
. - Godoc: https://godoc.org/gopkg.in/labstack/echo.v1
- Docs: https://github.com/labstack/echo/tree/v1.4/website/content
- Installation: Use a package manager (https://github.com/Masterminds/glide, it's nice!) to get stable v1 release/commit or use
Echo
Fast and unfancy HTTP server framework for Go (Golang). Up to 10x faster than the rest.
Feature Overview
- Optimized HTTP router which smartly prioritize routes.
- Build robust and scalable RESTful APIs.
- Run with standard HTTP server or FastHTTP server.
- Group APIs.
- Extensible middleware framework.
- Define middleware at root, group or route level.
- Data binding for JSON, XML and form payload.
- Handy functions to send variety of HTTP responses.
- Centralized HTTP error handling.
- Template rendering with any template engine.
- Define your format for the logger.
- Highly customizable.
Performance
- Environment:
- Go 1.6
- wrk 4.0.0
- 2 GB, 2 Core (DigitalOcean)
- Test Suite: https://github.com/vishr/web-framework-benchmark
- Date: 4/4/2016
Quick Start
Installation
$ go get github.com/labstack/echo/...
Hello, World!
Create server.go
package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Run(standard.New(":1323"))
}
Start server
$ go run server.go
Browse to http://localhost:1323 and you should see Hello, World! on the page.
Routing
e.POST("/users", saveUser)
e.GET("/users/:id", getUser)
e.PUT("/users/:id", updateUser)
e.DELETE("/users/:id", deleteUser)
Path Parameters
func getUser(c echo.Context) error {
// User ID from path `users/:id`
id := c.Param("id")
}
Query Parameters
/show?team=x-men&member=wolverine
func show(c echo.Context) error {
// Get team and member from the query string
team := c.QueryParam("team")
member := c.QueryParam("member")
}
Form application/x-www-form-urlencoded
POST
/save
name | value |
---|---|
name | Joe Smith |
joe@labstack.com |
func save(c echo.Context) error {
// Get name and email
name := c.FormValue("name")
email := c.FormValue("email")
}
Form multipart/form-data
POST
/save
name | value |
---|---|
name | Joe Smith |
joe@labstack.com | |
avatar | avatar |
func save(c echo.Context) error {
// Get name and email
name := c.FormValue("name")
email := c.FormValue("email")
// Get avatar
avatar, err := c.FormFile("avatar")
if err != nil {
return err
}
// Source
src, err := avatar.Open()
if err != nil {
return err
}
defer src.Close()
// Destination
dst, err := os.Create(avatar.Filename)
if err != nil {
return err
}
defer dst.Close()
// Copy
if _, err = io.Copy(dst, src); err != nil {
return err
}
return c.HTML(http.StatusOK, "<b>Thank you!</b>")
}
Handling Request
- Bind
JSON
orXML
orform
payload into Go struct based onContent-Type
request header. - Render response as
JSON
orXML
with status code.
type User struct {
Name string `json:"name" xml:"name" form:"name"`
Email string `json:"email" xml:"email" form:"email"`
}
e.POST("/users", func(c echo.Context) error {
u := new(User)
if err := c.Bind(u); err != nil {
return err
}
return c.JSON(http.StatusCreated, u)
// or
// return c.XML(http.StatusCreated, u)
})
Static Content
Server any file from static directory for path /static/*
.
e.Static("/static", "static")
Template Rendering
Middleware
// Root level middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Group level middleware
g := e.Group("/admin")
g.Use(middleware.BasicAuth(func(username, password string) bool {
if username == "joe" && password == "secret" {
return true
}
return false
}))
// Route level middleware
track := func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
println("request to /users")
return next(c)
}
}
e.GET("/users", func(c echo.Context) error {
return c.String(http.StatusOK, "/users")
}, track)
Built-in Middleware
Middleware | Description |
---|---|
BodyLimit | Limit request body |
Logger | Log HTTP requests |
Recover | Recover from panics |
Gzip | Send gzip HTTP response |
BasicAuth | HTTP basic authentication |
JWTAuth | JWT authentication |
Secure | Protection against attacks |
CORS | Cross-Origin Resource Sharing |
CSRF | Cross-Site Request Forgery |
Static | Serve static files |
AddTrailingSlash | Add trailing slash to the request URI |
RemoveTrailingSlash | Remove trailing slash from the request URI |
MethodOverride | Override request method |
Third-party Middleware
Middleware | Description |
---|---|
echoperm | Keeping track of users, login states and permissions. |
Next
Need help?
Support Us
- ⭐ the project
- Donate
- 🌎 spread the word
- Contribute to the project
Contribute
Use issues for everything
- Report issues
- Discuss on chat before sending a pull request
- Suggest new features or enhancements
- Improve/fix documentation
Credits
- Vishal Rana - Author
- Nitin Rana - Consultant
- Contributors
License
Documentation ¶
Overview ¶
Package echo implements a fast and unfancy HTTP server framework for Go (Golang).
Example:
package main import ( "net/http" "github.com/labstack/echo" "github.com/labstack/echo/engine/standard" "github.com/labstack/echo/middleware" ) // Handler func hello(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") } func main() { // Echo instance e := echo.New() // Middleware e.Use(middleware.Logger()) e.Use(middleware.Recover()) // Routes e.GET("/", hello) // Start server e.Run(standard.New(":1323")) }
Learn more at https://echo.labstack.com
Index ¶
- Constants
- Variables
- func ContentTypeByExtension(name string) (t string)
- type Binder
- type Context
- type Cookie
- func (c *Cookie) Domain() string
- func (c *Cookie) Expires() time.Time
- func (c *Cookie) HTTPOnly() bool
- func (c *Cookie) Name() string
- func (c *Cookie) Path() string
- func (c *Cookie) Secure() bool
- func (c *Cookie) SetDomain(domain string)
- func (c *Cookie) SetExpires(expires time.Time)
- func (c *Cookie) SetHTTPOnly(httpOnly bool)
- func (c *Cookie) SetName(name string)
- func (c *Cookie) SetPath(path string)
- func (c *Cookie) SetSecure(secure bool)
- func (c *Cookie) SetValue(value string)
- func (c *Cookie) Value() string
- type Echo
- func (e *Echo) AcquireContext() Context
- func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
- func (e *Echo) Binder() Binder
- func (e *Echo) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Connect(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Debug() bool
- func (e *Echo) DefaultHTTPErrorHandler(err error, c Context)
- func (e *Echo) Delete(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) File(path, file string)
- func (e *Echo) GET(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Get(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Group(prefix string, m ...MiddlewareFunc) (g *Group)
- func (e *Echo) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Head(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Logger() log.Logger
- func (e *Echo) Match(methods []string, path string, handler HandlerFunc, ...)
- func (e *Echo) NewContext(req engine.Request, res engine.Response) Context
- func (e *Echo) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Options(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) POST(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) PUT(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Patch(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Post(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Pre(middleware ...MiddlewareFunc)
- func (e *Echo) Put(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) ReleaseContext(c Context)
- func (e *Echo) Router() *Router
- func (e *Echo) Routes() []Route
- func (e *Echo) Run(s engine.Server)
- func (e *Echo) ServeHTTP(req engine.Request, res engine.Response)
- func (e *Echo) SetBinder(b Binder)
- func (e *Echo) SetDebug(on bool)
- func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
- func (e *Echo) SetLogLevel(l uint8)
- func (e *Echo) SetLogOutput(w io.Writer)
- func (e *Echo) SetLogger(l log.Logger)
- func (e *Echo) SetRenderer(r Renderer)
- func (e *Echo) Static(prefix, root string)
- func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) Trace(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (e *Echo) URI(handler HandlerFunc, params ...interface{}) string
- func (e *Echo) URL(h HandlerFunc, params ...interface{}) string
- func (e *Echo) Use(middleware ...MiddlewareFunc)
- type Group
- func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
- func (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Connect(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Delete(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) File(path, file string)
- func (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Get(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Group(prefix string, m ...MiddlewareFunc) *Group
- func (g *Group) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Head(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Match(methods []string, path string, handler HandlerFunc, ...)
- func (g *Group) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Options(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) POST(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) PUT(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Patch(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Post(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Put(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Static(prefix, root string)
- func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Trace(path string, h HandlerFunc, m ...MiddlewareFunc)
- func (g *Group) Use(m ...MiddlewareFunc)
- type HTTPError
- type HTTPErrorHandler
- type HandlerFunc
- type MiddlewareFunc
- type Renderer
- type Route
- type Router
- type Validator
Constants ¶
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" TRACE = "TRACE" )
HTTP methods
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
const ( HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXCSRFToken = "X-CSRF-Token" )
Headers
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrCookieNotFound = errors.New("cookie not found") )
Errors
Functions ¶
func ContentTypeByExtension ¶
ContentTypeByExtension returns the MIME type associated with the file based on its extension. It returns `application/octet-stream` incase MIME type is not found.
Types ¶
type Context ¶
type Context interface { // Context returns `net/context.Context`. Context() context.Context // SetContext sets `net/context.Context`. SetContext(context.Context) // Deadline returns the time when work done on behalf of this context // should be canceled. Deadline returns ok==false when no deadline is // set. Successive calls to Deadline return the same results. Deadline() (deadline time.Time, ok bool) // Done returns a channel that's closed when work done on behalf of this // context should be canceled. Done may return nil if this context can // never be canceled. Successive calls to Done return the same value. Done() <-chan struct{} // Err returns a non-nil error value after Done is closed. Err returns // Canceled if the context was canceled or DeadlineExceeded if the // context's deadline passed. No other values for Err are defined. // After Done is closed, successive calls to Err return the same value. Err() error // Value returns the value associated with this context for key, or nil // if no value is associated with key. Successive calls to Value with // the same key returns the same result. Value(key interface{}) interface{} // Request returns `engine.Request` interface. Request() engine.Request // Request returns `engine.Response` interface. Response() engine.Response // Path returns the registered path for the handler. Path() string // SetPath sets the registered path for the handler. SetPath(string) // P returns path parameter by index. P(int) string // Param returns path parameter by name. Param(string) string // ParamNames returns path parameter names. ParamNames() []string // SetParamNames sets path parameter names. SetParamNames(...string) // ParamValues returns path parameter values. ParamValues() []string // SetParamValues sets path parameter values. SetParamValues(...string) // QueryParam returns the query param for the provided name. It is an alias // for `engine.URL#QueryParam()`. QueryParam(string) string // QueryParams returns the query parameters as map. // It is an alias for `engine.URL#QueryParams()`. QueryParams() map[string][]string // FormValue returns the form field value for the provided name. It is an // alias for `engine.Request#FormValue()`. FormValue(string) string // FormParams returns the form parameters as map. // It is an alias for `engine.Request#FormParams()`. FormParams() map[string][]string // FormFile returns the multipart form file for the provided name. It is an // alias for `engine.Request#FormFile()`. FormFile(string) (*multipart.FileHeader, error) // MultipartForm returns the multipart form. // It is an alias for `engine.Request#MultipartForm()`. MultipartForm() (*multipart.Form, error) // Cookie returns the named cookie provided in the request. // It is an alias for `engine.Request#Cookie()`. Cookie(string) (engine.Cookie, error) // SetCookie adds a `Set-Cookie` header in HTTP response. // It is an alias for `engine.Response#SetCookie()`. SetCookie(engine.Cookie) // Cookies returns the HTTP cookies sent with the request. // It is an alias for `engine.Request#Cookies()`. Cookies() []engine.Cookie // Get retrieves data from the context. Get(string) interface{} // Set saves data in the context. Set(string, interface{}) // Bind binds the request body into provided type `i`. The default binder // does it based on Content-Type header. Bind(interface{}) error // Render renders a template with data and sends a text/html response with status // code. Templates can be registered using `Echo.SetRenderer()`. Render(int, string, interface{}) error // HTML sends an HTTP response with status code. HTML(int, string) error // String sends a string response with status code. String(int, string) error // JSON sends a JSON response with status code. JSON(int, interface{}) error // JSONBlob sends a JSON blob response with status code. JSONBlob(int, []byte) error // JSONP sends a JSONP response with status code. It uses `callback` to construct // the JSONP payload. JSONP(int, string, interface{}) error // XML sends an XML response with status code. XML(int, interface{}) error // XMLBlob sends a XML blob response with status code. XMLBlob(int, []byte) error // File sends a response with the content of the file. File(string) error // Attachment sends a response from `io.ReaderSeeker` as attachment, prompting // client to save the file. Attachment(io.ReadSeeker, string) error // NoContent sends a response with no body and a status code. NoContent(int) error // Redirect redirects the request with status code. Redirect(int, string) error // Error invokes the registered HTTP error handler. Generally used by middleware. Error(err error) // Handler returns the matched handler by router. Handler() HandlerFunc // SetHandler sets the matched handler by router. SetHandler(HandlerFunc) // Logger returns the `Logger` instance. Logger() log.Logger // Echo returns the `Echo` instance. Echo() *Echo // ServeContent sends static content from `io.Reader` and handles caching // via `If-Modified-Since` request header. It automatically sets `Content-Type` // and `Last-Modified` response headers. ServeContent(io.ReadSeeker, string, time.Time) error // Reset resets the context after request completes. It must be called along // with `Echo#AcquireContext()` and `Echo#ReleaseContext()`. // See `Echo#ServeHTTP()` Reset(engine.Request, engine.Response) }
Context represents the context of the current HTTP request. It holds request and response objects, path, path parameters, data and registered handler.
type Cookie ¶
type Cookie struct {
// contains filtered or unexported fields
}
Cookie defines the HTTP cookie.
func (*Cookie) SetExpires ¶
SetExpires sets the cookie expiry time.
func (*Cookie) SetHTTPOnly ¶
SetHTTPOnly sets the cookie as HTTPOnly.
type Echo ¶
type Echo struct {
// contains filtered or unexported fields
}
Echo is the top-level framework instance.
func (*Echo) AcquireContext ¶
AcquireContext returns an empty `Context` instance from the pool. You must be return the context by calling `ReleaseContext()`.
func (*Echo) Any ¶ added in v1.2.0
func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
Any registers a new route for all HTTP methods and path with matching handler in the router with optional route-level middleware.
func (*Echo) CONNECT ¶
func (e *Echo) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc)
CONNECT registers a new CONNECT route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Connect ¶
func (e *Echo) Connect(path string, h HandlerFunc, m ...MiddlewareFunc)
Connect is deprecated, use `CONNECT()` instead.
func (*Echo) DELETE ¶
func (e *Echo) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc)
DELETE registers a new DELETE route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) DefaultHTTPErrorHandler ¶ added in v1.0.0
DefaultHTTPErrorHandler invokes the default HTTP error handler.
func (*Echo) Delete ¶
func (e *Echo) Delete(path string, h HandlerFunc, m ...MiddlewareFunc)
Delete is deprecated, use `DELETE()` instead.
func (*Echo) GET ¶
func (e *Echo) GET(path string, h HandlerFunc, m ...MiddlewareFunc)
GET registers a new GET route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Get ¶
func (e *Echo) Get(path string, h HandlerFunc, m ...MiddlewareFunc)
Get is deprecated, use `GET()` instead.
func (*Echo) Group ¶ added in v0.0.4
func (e *Echo) Group(prefix string, m ...MiddlewareFunc) (g *Group)
Group creates a new router group with prefix and optional group-level middleware.
func (*Echo) HEAD ¶
func (e *Echo) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc)
HEAD registers a new HEAD route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Head ¶
func (e *Echo) Head(path string, h HandlerFunc, m ...MiddlewareFunc)
Head is deprecated, use `HEAD()` instead.
func (*Echo) Match ¶ added in v1.2.0
func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc)
Match registers a new route for multiple HTTP methods and path with matching handler in the router with optional route-level middleware.
func (*Echo) NewContext ¶
NewContext returns a Context instance.
func (*Echo) OPTIONS ¶
func (e *Echo) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc)
OPTIONS registers a new OPTIONS route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Options ¶
func (e *Echo) Options(path string, h HandlerFunc, m ...MiddlewareFunc)
Options is deprecated, use `OPTIONS()` instead.
func (*Echo) PATCH ¶
func (e *Echo) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc)
PATCH registers a new PATCH route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) POST ¶
func (e *Echo) POST(path string, h HandlerFunc, m ...MiddlewareFunc)
POST registers a new POST route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) PUT ¶
func (e *Echo) PUT(path string, h HandlerFunc, m ...MiddlewareFunc)
PUT registers a new PUT route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Patch ¶
func (e *Echo) Patch(path string, h HandlerFunc, m ...MiddlewareFunc)
Patch is deprecated, use `PATCH()` instead.
func (*Echo) Post ¶
func (e *Echo) Post(path string, h HandlerFunc, m ...MiddlewareFunc)
Post is deprecated, use `POST()` instead.
func (*Echo) Pre ¶
func (e *Echo) Pre(middleware ...MiddlewareFunc)
Pre adds middleware to the chain which is run before router.
func (*Echo) Put ¶
func (e *Echo) Put(path string, h HandlerFunc, m ...MiddlewareFunc)
Put is deprecated, use `PUT()` instead.
func (*Echo) ReleaseContext ¶
ReleaseContext returns the `Context` instance back to the pool. You must call it after `AcquireContext()`.
func (*Echo) SetBinder ¶ added in v0.0.14
SetBinder registers a custom binder. It's invoked by `Context#Bind()`.
func (*Echo) SetHTTPErrorHandler ¶ added in v0.0.14
func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler)
SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
func (*Echo) SetLogLevel ¶ added in v1.4.1
SetLogLevel sets the log level for the logger. Default value `3` (ERROR).
func (*Echo) SetLogOutput ¶ added in v1.4.1
SetLogOutput sets the output destination for the logger. Default value is `os.Std*`
func (*Echo) SetRenderer ¶ added in v0.0.14
SetRenderer registers an HTML template renderer. It's invoked by `Context#Render()`.
func (*Echo) Static ¶
Static registers a new route with path prefix to serve static files from the provided root directory.
func (*Echo) TRACE ¶
func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc)
TRACE registers a new TRACE route for a path with matching handler in the router with optional route-level middleware.
func (*Echo) Trace ¶
func (e *Echo) Trace(path string, h HandlerFunc, m ...MiddlewareFunc)
Trace is deprecated, use `TRACE()` instead.
func (*Echo) URI ¶ added in v0.0.11
func (e *Echo) URI(handler HandlerFunc, params ...interface{}) string
URI generates a URI from handler.
func (*Echo) URL ¶ added in v0.0.11
func (e *Echo) URL(h HandlerFunc, params ...interface{}) string
URL is an alias for `URI` function.
func (*Echo) Use ¶
func (e *Echo) Use(middleware ...MiddlewareFunc)
Use adds middleware to the chain which is run after router.
type Group ¶ added in v0.0.16
type Group struct {
// contains filtered or unexported fields
}
Group is a set of sub-routes for a specified route. It can be used for inner routes that share a common middlware or functionality that should be separate from the parent echo instance while still inheriting from it.
func (*Group) Any ¶ added in v1.4.1
func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc)
Any implements `Echo#Any()` for sub-routes within the Group.
func (*Group) CONNECT ¶
func (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc)
CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
func (*Group) Connect ¶ added in v0.0.16
func (g *Group) Connect(path string, h HandlerFunc, m ...MiddlewareFunc)
Connect is deprecated, use `CONNECT()` instead.
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc)
DELETE implements `Echo#DELETE()` for sub-routes within the Group.
func (*Group) Delete ¶ added in v0.0.16
func (g *Group) Delete(path string, h HandlerFunc, m ...MiddlewareFunc)
Delete is deprecated, use `DELETE()` instead.
func (*Group) GET ¶
func (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc)
GET implements `Echo#GET()` for sub-routes within the Group.
func (*Group) Get ¶ added in v0.0.16
func (g *Group) Get(path string, h HandlerFunc, m ...MiddlewareFunc)
Get is deprecated, use `GET()` instead.
func (*Group) Group ¶ added in v0.0.16
func (g *Group) Group(prefix string, m ...MiddlewareFunc) *Group
Group creates a new sub-group with prefix and optional sub-group-level middleware.
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc)
HEAD implements `Echo#HEAD()` for sub-routes within the Group.
func (*Group) Head ¶ added in v0.0.16
func (g *Group) Head(path string, h HandlerFunc, m ...MiddlewareFunc)
Head is deprecated, use `HEAD()` instead.
func (*Group) Match ¶ added in v1.4.1
func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc)
Match implements `Echo#Match()` for sub-routes within the Group.
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc)
OPTIONS implements `Echo#OPTIONS()` for sub-routes within the Group.
func (*Group) Options ¶ added in v0.0.16
func (g *Group) Options(path string, h HandlerFunc, m ...MiddlewareFunc)
Options is deprecated, use `OPTIONS()` instead.
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc)
PATCH implements `Echo#PATCH()` for sub-routes within the Group.
func (*Group) POST ¶
func (g *Group) POST(path string, h HandlerFunc, m ...MiddlewareFunc)
POST implements `Echo#POST()` for sub-routes within the Group.
func (*Group) PUT ¶
func (g *Group) PUT(path string, h HandlerFunc, m ...MiddlewareFunc)
PUT implements `Echo#PUT()` for sub-routes within the Group.
func (*Group) Patch ¶ added in v0.0.16
func (g *Group) Patch(path string, h HandlerFunc, m ...MiddlewareFunc)
Patch is deprecated, use `PATCH()` instead.
func (*Group) Post ¶ added in v0.0.16
func (g *Group) Post(path string, h HandlerFunc, m ...MiddlewareFunc)
Post is deprecated, use `POST()` instead.
func (*Group) Put ¶ added in v0.0.16
func (g *Group) Put(path string, h HandlerFunc, m ...MiddlewareFunc)
Put is deprecated, use `PUT()` instead.
func (*Group) Static ¶ added in v1.0.0
Static implements `Echo#Static()` for sub-routes within the Group.
func (*Group) TRACE ¶
func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc)
TRACE implements `Echo#TRACE()` for sub-routes within the Group.
func (*Group) Trace ¶ added in v0.0.16
func (g *Group) Trace(path string, h HandlerFunc, m ...MiddlewareFunc)
Trace is deprecated, use `TRACE()` instead.
func (*Group) Use ¶ added in v0.0.16
func (g *Group) Use(m ...MiddlewareFunc)
Use implements `Echo#Use()` for sub-routes within the Group.
type HTTPError ¶ added in v0.0.12
HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶ added in v0.0.14
NewHTTPError creates a new HTTPError instance.
type HTTPErrorHandler ¶ added in v0.0.10
HTTPErrorHandler is a centralized HTTP error handler.
type HandlerFunc ¶
HandlerFunc defines a function to server HTTP requests.
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc defines a function to process middleware.
func WrapMiddleware ¶
func WrapMiddleware(h HandlerFunc) MiddlewareFunc
WrapMiddleware wrap `echo.HandlerFunc` into `echo.MiddlewareFunc`.
type Route ¶ added in v1.0.0
Route contains a handler and information for matching against requests.
type Router ¶ added in v0.0.16
type Router struct {
// contains filtered or unexported fields
}
Router is the registry of all registered routes for an `Echo` instance for request matching and URL path parameter parsing.
func (*Router) Add ¶ added in v0.0.16
func (r *Router) Add(method, path string, h HandlerFunc, e *Echo)
Add registers a new route for method and path with matching handler.