mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
More coverage
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
12c84aed07
commit
d9185ddf5c
18
echo.go
18
echo.go
@ -102,9 +102,10 @@ var (
|
|||||||
|
|
||||||
// New creates an Echo instance.
|
// New creates an Echo instance.
|
||||||
func New() (e *Echo) {
|
func New() (e *Echo) {
|
||||||
e = &Echo{}
|
e = &Echo{
|
||||||
|
uris: make(map[Handler]string),
|
||||||
|
}
|
||||||
e.Router = NewRouter(e)
|
e.Router = NewRouter(e)
|
||||||
e.uris = make(map[Handler]string)
|
|
||||||
e.pool.New = func() interface{} {
|
e.pool.New = func() interface{} {
|
||||||
return &Context{
|
return &Context{
|
||||||
Response: &response{},
|
Response: &response{},
|
||||||
@ -117,19 +118,18 @@ func New() (e *Echo) {
|
|||||||
//----------
|
//----------
|
||||||
// Defaults
|
// Defaults
|
||||||
//----------
|
//----------
|
||||||
e.maxParam = 5
|
e.MaxParam(5)
|
||||||
e.notFoundHandler = HandlerFunc(func(c *Context) error {
|
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)
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
e.httpErrorHandler = func(err error, c *Context) {
|
e.HTTPErrorHandler(func(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(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
e.binder = func(r *http.Request, v interface{}) error {
|
e.Binder(func(r *http.Request, v interface{}) error {
|
||||||
ct := r.Header.Get(HeaderContentType)
|
ct := r.Header.Get(HeaderContentType)
|
||||||
if strings.HasPrefix(ct, MIMEJSON) {
|
if strings.HasPrefix(ct, MIMEJSON) {
|
||||||
return json.NewDecoder(r.Body).Decode(v)
|
return json.NewDecoder(r.Body).Decode(v)
|
||||||
@ -137,7 +137,7 @@ func New() (e *Echo) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return UnsupportedMediaType
|
return UnsupportedMediaType
|
||||||
}
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user