1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-30 08:46:41 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-04-24 15:13:06 -07:00
parent bb206605da
commit eee38a6376
5 changed files with 32 additions and 11 deletions

View File

@ -80,8 +80,8 @@ func (c *Context) NoContent(code int) error {
} }
// Error invokes the registered HTTP error handler. // Error invokes the registered HTTP error handler.
func (c *Context) Error(err error) { func (c *Context) Error(code int, err error) {
c.echo.httpErrorHandler(err, c) c.echo.httpErrorHandler(code, err, c)
} }
// Get retrieves data from the context. // Get retrieves data from the context.

View File

@ -35,7 +35,7 @@ type (
HandlerFunc func(*Context) error HandlerFunc func(*Context) error
// HTTPErrorHandler is a centralized HTTP error handler. // HTTPErrorHandler is a centralized HTTP error handler.
HTTPErrorHandler func(error, *Context) HTTPErrorHandler func(int, error, *Context)
BindFunc func(*http.Request, interface{}) error BindFunc func(*http.Request, interface{}) error
@ -122,11 +122,11 @@ func New() (e *Echo) {
e.NotFoundHandler(func(c *Context) { e.NotFoundHandler(func(c *Context) {
http.Error(c.Response, http.StatusText(http.StatusNotFound), http.StatusNotFound) http.Error(c.Response, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}) })
e.HTTPErrorHandler(func(err error, c *Context) { e.HTTPErrorHandler(func(code int, err error, c *Context) {
if err != nil { if err != nil {
// TODO: Warning // TODO: Warning
log.Printf("echo: %s", color.Yellow("http error handler not registered")) log.Printf("echo: %s", color.Yellow("http error handler not registered"))
http.Error(c.Response, err.Error(), http.StatusInternalServerError) http.Error(c.Response, err.Error(), code)
} }
}) })
e.Binder(func(r *http.Request, v interface{}) error { e.Binder(func(r *http.Request, v interface{}) error {
@ -305,7 +305,7 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Execute chain // Execute chain
if err := h(c); err != nil { if err := h(c); err != nil {
e.httpErrorHandler(err, c) e.httpErrorHandler(http.StatusInternalServerError, err, c)
} }
e.pool.Put(c) e.pool.Put(c)

View File

@ -2,6 +2,7 @@ package middleware
import ( import (
"log" "log"
"net/http"
"time" "time"
"github.com/labstack/echo" "github.com/labstack/echo"
@ -12,7 +13,7 @@ func Logger(h echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error { return func(c *echo.Context) error {
start := time.Now() start := time.Now()
if err := h(c); err != nil { if err := h(c); err != nil {
c.Error(err) c.Error(http.StatusInternalServerError, err)
} }
end := time.Now() end := time.Now()
m := c.Request.Method m := c.Request.Method

View File

@ -1 +1,19 @@
# Coming soon... # Guide
---
## Installation
Go `~1.4.2`
Install the latest version of Echo `go get github.com/labstack/echo`
Upgrade Echo `go get -u github.com/labstack/echo`
### Using package manager
## Routing
## Request
## Response

View File

@ -35,12 +35,14 @@ Echo is a fast HTTP router (zero memory allocation) and micro web framework in G
- Use a customized function to bind request body to a Go type. - Use a customized function to bind request body to a Go type.
- Register a view render so you can use any HTML templating engine. - Register a view render so you can use any HTML templating engine.
## Installation ## Getting Started
- [Go](https://golang.org/doc/install) > 1.4.x ### Installation
- Go `~1.4.2`
- `go get github.com/labstack/echo` - `go get github.com/labstack/echo`
##[Examples](https://github.com/labstack/echo/tree/master/examples) ###[Examples](https://github.com/labstack/echo/tree/master/examples)
> Hello, World! > Hello, World!