mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Updated website
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
ba05b6e58e
commit
8abd4faf08
2
echo.go
2
echo.go
@ -293,7 +293,7 @@ func (e *Echo) add(method, path string, h Handler) {
|
||||
// Static serves static files.
|
||||
func (e *Echo) Static(path, root string) {
|
||||
fs := http.StripPrefix(path, http.FileServer(http.Dir(root)))
|
||||
e.Get(path+"/*", func(c *Context) *HTTPError {
|
||||
e.Get(path+"*", func(c *Context) *HTTPError {
|
||||
fs.ServeHTTP(c.Response, c.Request)
|
||||
return nil
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ func main() {
|
||||
e.Favicon("public/favicon.ico")
|
||||
|
||||
// Serve static files
|
||||
e.Static("/scripts", "public/scripts")
|
||||
e.Static("/scripts/", "public/scripts")
|
||||
|
||||
//--------
|
||||
// Routes
|
||||
|
@ -193,18 +193,17 @@ Sends an HTML HTTP response with status code.
|
||||
|
||||
### Static files
|
||||
|
||||
`echo.Static(path, root string)` serves static files. For example, code below
|
||||
serves all files from `public/scripts` directory for any path starting
|
||||
with `/scripts/`
|
||||
`echo.Static(path, root string)` serves static files. For example, code below serves
|
||||
files from directory `public/scripts` for any URL path starting with `/scripts/`.
|
||||
|
||||
```go
|
||||
e.Static("/scripts", "public/scripts")
|
||||
e.Static("/scripts/", "public/scripts")
|
||||
```
|
||||
|
||||
### Serving a file
|
||||
|
||||
`echo.ServeFile(path, file string)` serves a file. For example, code below serves
|
||||
welcome.html for path `/welcome`
|
||||
file `welcome.html` for URL path `/welcome`.
|
||||
|
||||
```go
|
||||
e.ServeFile("/welcome", "welcome.html")
|
||||
@ -212,13 +211,22 @@ e.ServeFile("/welcome", "welcome.html")
|
||||
|
||||
### Serving an index file
|
||||
|
||||
`echo.Index(file string)` serves an index file. For example, code below serves
|
||||
index.html for path `/`
|
||||
`echo.Index(file string)` serves an index file. For example, code below serves file
|
||||
`index.html`.
|
||||
|
||||
```go
|
||||
e.Index("index.html")
|
||||
```
|
||||
|
||||
### Serving favicon
|
||||
|
||||
`echo.Favicon(file string)` serves default favicon - `GET /favicon.ico`. For example,
|
||||
code below serves file `favicon.ico`.
|
||||
|
||||
```go
|
||||
e.Index("public/favicon.ico")
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
Echo advocates centralized HTTP error handling by returning `*echo.HTTPError` from
|
||||
|
Loading…
Reference in New Issue
Block a user