1
0
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:
Vishal Rana 2015-04-21 22:28:17 -07:00
parent 8d3cd84852
commit 34d100dee9

26
echo.go
View File

@ -48,14 +48,23 @@ type (
) )
const ( const (
// CONNECT HTTP method
CONNECT = "CONNECT" CONNECT = "CONNECT"
// DELETE HTTP method
DELETE = "DELETE" DELETE = "DELETE"
// GET HTTP method
GET = "GET" GET = "GET"
// HEAD HTTP method
HEAD = "HEAD" HEAD = "HEAD"
// OPTIONS HTTP method
OPTIONS = "OPTIONS" OPTIONS = "OPTIONS"
// PATCH HTTP method
PATCH = "PATCH" PATCH = "PATCH"
// POST HTTP method
POST = "POST" POST = "POST"
// PUT HTTP method
PUT = "PUT" PUT = "PUT"
// TRACE HTTP method
TRACE = "TRACE" TRACE = "TRACE"
MIMEJSON = "application/json" MIMEJSON = "application/json"
@ -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
} }