mirror of
https://github.com/labstack/echo.git
synced 2025-05-13 22:06:36 +02:00
Improved godoc
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
8d3cd84852
commit
34d100dee9
40
echo.go
40
echo.go
@ -48,15 +48,24 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// CONNECT HTTP method
|
||||||
CONNECT = "CONNECT"
|
CONNECT = "CONNECT"
|
||||||
DELETE = "DELETE"
|
// DELETE HTTP method
|
||||||
GET = "GET"
|
DELETE = "DELETE"
|
||||||
HEAD = "HEAD"
|
// GET HTTP method
|
||||||
|
GET = "GET"
|
||||||
|
// HEAD HTTP method
|
||||||
|
HEAD = "HEAD"
|
||||||
|
// OPTIONS HTTP method
|
||||||
OPTIONS = "OPTIONS"
|
OPTIONS = "OPTIONS"
|
||||||
PATCH = "PATCH"
|
// PATCH HTTP method
|
||||||
POST = "POST"
|
PATCH = "PATCH"
|
||||||
PUT = "PUT"
|
// POST HTTP method
|
||||||
TRACE = "TRACE"
|
POST = "POST"
|
||||||
|
// PUT HTTP method
|
||||||
|
PUT = "PUT"
|
||||||
|
// TRACE HTTP method
|
||||||
|
TRACE = "TRACE"
|
||||||
|
|
||||||
MIMEJSON = "application/json"
|
MIMEJSON = "application/json"
|
||||||
MIMEText = "text/plain"
|
MIMEText = "text/plain"
|
||||||
@ -83,7 +92,10 @@ var (
|
|||||||
TRACE,
|
TRACE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------
|
||||||
// Errors
|
// Errors
|
||||||
|
//--------
|
||||||
|
|
||||||
UnsupportedMediaType = errors.New("echo: unsupported media type")
|
UnsupportedMediaType = errors.New("echo: unsupported media type")
|
||||||
RendererNotRegistered = errors.New("echo: renderer not registered")
|
RendererNotRegistered = errors.New("echo: renderer not registered")
|
||||||
)
|
)
|
||||||
@ -105,18 +117,19 @@ func New() (e *Echo) {
|
|||||||
//----------
|
//----------
|
||||||
// Defaults
|
// Defaults
|
||||||
//----------
|
//----------
|
||||||
e.MaxParam(5)
|
e.maxParam = 5
|
||||||
e.NotFoundHandler(func(c *Context) {
|
e.notFoundHandler = HandlerFunc(func(c *Context) error {
|
||||||
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)
|
||||||
@ -124,8 +137,7 @@ func New() (e *Echo) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return UnsupportedMediaType
|
return UnsupportedMediaType
|
||||||
})
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user