1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-22 20:06:21 +02:00
echo/website/content/guide/customization.md
Vishal Rana 770858c6e6 Merge pull request #300 from 01walid/patch-2
Fix a small typo in customization docs
2016-01-26 08:03:20 -08:00

1.8 KiB

title menu
Customization
side
parent weight
guide 2

HTTP error handler

Echo#SetHTTPErrorHandler(h HTTPErrorHandler)

Registers a custom Echo#HTTPErrorHandler.

Default handler rules:

  • If error is of type Echo#HTTPError it sends HTTP response with status code HTTPError.Code and message HTTPError.Message.
  • Else it sends 500 - Internal Server Error.
  • If debug mode is enabled, it uses error.Error() as status message.

Debug

Echo#SetDebug(on bool)

Enable/disable debug mode.

Log prefix

echo#SetLogPrefix(prefix string)

SetLogPrefix sets the prefix for the logger. Default value is echo.

Log output

echo#SetLogOutput(w io.Writer)

SetLogOutput sets the output destination for the logger. Default value is os.Stdout

Log level

echo#SetLogLevel(l log.Level)

SetLogLevel sets the log level for the logger. Default value is log.INFO.

HTTP2

echo#HTTP2(on bool)

Enable/disable HTTP2 support.

Auto index

Echo#AutoIndex(on bool)

Enable/disable automatically creating an index page for the directory.

Example

e := echo.New()
e.AutoIndex(true)
e.ServeDir("/", "/Users/vr/Projects/echo")
e.Run(":1323")

Browse to http://localhost:1323/ to see the directory listing.

Hook

Echo#Hook(h http.HandlerFunc)

Hook registers a callback which is invoked from Echo#ServerHTTP as the first statement. Hook is useful if you want to modify response/response objects even before it hits the router or any middleware.

For example, the following hook strips the trailing slash from the request path.

e.Hook(func(w http.ResponseWriter, r *http.Request) {
    path := r.URL.Path
    l := len(path) - 1
    if path != "/" && path[l] == '/' {
        r.URL.Path = path[:l]
    }
})