1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +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.
func (c *Context) Error(err error) {
c.echo.httpErrorHandler(err, c)
func (c *Context) Error(code int, err error) {
c.echo.httpErrorHandler(code, err, c)
}
// Get retrieves data from the context.

View File

@ -35,7 +35,7 @@ type (
HandlerFunc func(*Context) error
// HTTPErrorHandler is a centralized HTTP error handler.
HTTPErrorHandler func(error, *Context)
HTTPErrorHandler func(int, error, *Context)
BindFunc func(*http.Request, interface{}) error
@ -122,11 +122,11 @@ func New() (e *Echo) {
e.NotFoundHandler(func(c *Context) {
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 {
// TODO: Warning
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 {
@ -305,7 +305,7 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Execute chain
if err := h(c); err != nil {
e.httpErrorHandler(err, c)
e.httpErrorHandler(http.StatusInternalServerError, err, c)
}
e.pool.Put(c)

View File

@ -2,6 +2,7 @@ package middleware
import (
"log"
"net/http"
"time"
"github.com/labstack/echo"
@ -12,7 +13,7 @@ func Logger(h echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
start := time.Now()
if err := h(c); err != nil {
c.Error(err)
c.Error(http.StatusInternalServerError, err)
}
end := time.Now()
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.
- 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`
##[Examples](https://github.com/labstack/echo/tree/master/examples)
###[Examples](https://github.com/labstack/echo/tree/master/examples)
> Hello, World!