Skip to content

Commit c020919

Browse files
committed
Updated website
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent c0571e3 commit c020919

37 files changed

Lines changed: 1177 additions & 601 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Website
2-
site
2+
public
33
.publish
44

55
# Node.js

website/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM busybox
2+
MAINTAINER Vishal Rana <vr@labstack.com>
3+
4+
COPY server /server
5+
COPY public /public
6+
7+
CMD ["/server"]

website/config.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"baseurl": "http://labstack.com/echo",
3+
"languageCode": "en-us",
4+
"title": "Echo",
5+
6+
"menu": {
7+
"main": [{
8+
"Name": "Guide",
9+
"Pre": "<i class='fa fa-heart'></i>",
10+
"Weight": -110,
11+
"Identifier": "guide",
12+
"URL": "guide"
13+
}, {
14+
"Name": "Recipes",
15+
"Pre": "<i class='fa fa-road'></i>",
16+
"Weight": -100,
17+
"Identifier": "recipes",
18+
"URL": "recipes"
19+
}]
20+
},
21+
22+
"params": {
23+
"googleAnayticsId": "UA-51208124-3"
24+
}
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Customization
3+
menu:
4+
main:
5+
parent: guide
6+
---
7+
8+
### HTTP error handler
9+
10+
`Echo.SetHTTPErrorHandler(h HTTPErrorHandler)`
11+
12+
Registers a custom `Echo.HTTPErrorHandler`.
13+
14+
Default handler rules
15+
16+
- If error is of type `Echo.HTTPError` it sends HTTP response with status code `HTTPError.Code`
17+
and message `HTTPError.Message`.
18+
- Else it sends `500 - Internal Server Error`.
19+
- If debug mode is enabled, it uses `error.Error()` as status message.
20+
21+
### Debug
22+
23+
`Echo.SetDebug(on bool)`
24+
25+
Enables/disables debug mode.
26+
27+
### Disable colored log
28+
29+
`Echo.DisableColoredLog()`
30+
31+
### StripTrailingSlash
32+
33+
StripTrailingSlash enables removing trailing slash from the request path.
34+
35+
`e.StripTrailingSlash()`
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Error Handling
3+
menu:
4+
main:
5+
parent: guide
6+
---
7+
8+
Echo advocates centralized HTTP error handling by returning `error` from middleware
9+
and handlers.
10+
11+
It allows you to
12+
13+
- Debug by writing stack trace to the HTTP response.
14+
- Customize HTTP responses.
15+
- Recover from panics inside middleware or handlers.
16+
17+
For example, when basic auth middleware finds invalid credentials it returns
18+
`401 - Unauthorized` error, aborting the current HTTP request.
19+
20+
```go
21+
package main
22+
23+
import (
24+
"net/http"
25+
26+
"github.com/labstack/echo"
27+
)
28+
29+
func main() {
30+
e := echo.New()
31+
e.Use(func(c *echo.Context) error {
32+
// Extract the credentials from HTTP request header and perform a security
33+
// check
34+
35+
// For invalid credentials
36+
return echo.NewHTTPError(http.StatusUnauthorized)
37+
})
38+
e.Get("/welcome", welcome)
39+
e.Run(":1323")
40+
}
41+
42+
func welcome(c *echo.Context) error {
43+
return c.String(http.StatusOK, "Welcome!")
44+
}
45+
```
46+
47+
See how [HTTPErrorHandler](#customization) handles it.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Installation
3+
menu:
4+
main:
5+
parent: guide
6+
---
7+
8+
Echo has been developed and tested using Go `1.4.x`
9+
10+
Install the latest version of Echo via `go get`
11+
12+
```sh
13+
$ go get github.com/labstack/echo
14+
```
15+
16+
To upgrade
17+
18+
```sh
19+
$ go get -u github.com/labstack/echo
20+
```
21+
22+
Echo follows [semantic versioning](http://semver.org) managed through GitHub releases.
23+
Specific version of Echo can be installed using a [package manager](https://github.com/avelino/awesome-go#package-management).
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Middleware
3+
menu:
4+
main:
5+
parent: guide
6+
---
7+
8+
Middleware is a function which is chained in the HTTP request-response cycle. Middleware
9+
has access to the request and response objects which it utilizes to perform a specific
10+
action, for example, logging every request.
11+
12+
### Logger
13+
14+
Logs each HTTP request with method, path, status, response time and bytes served.
15+
16+
*Example*
17+
18+
```go
19+
e.Use(Logger())
20+
21+
// Output: `2015/06/07 18:16:16 GET / 200 13.238µs 14`
22+
```
23+
24+
### BasicAuth
25+
26+
BasicAuth middleware provides an HTTP basic authentication.
27+
28+
- For valid credentials it calls the next handler in the chain.
29+
- For invalid Authorization header it sends "404 - Bad Request" response.
30+
- For invalid credentials, it sends "401 - Unauthorized" response.
31+
32+
*Example*
33+
34+
```go
35+
e.Group("/admin")
36+
e.Use(mw.BasicAuth(func(usr, pwd string) bool {
37+
if usr == "joe" && pwd == "secret" {
38+
return true
39+
}
40+
return false
41+
}))
42+
```
43+
44+
### Gzip
45+
46+
Gzip middleware compresses HTTP response using gzip compression scheme.
47+
48+
*Example*
49+
50+
```go
51+
e.Use(mw.Gzip())
52+
```
53+
54+
### Recover
55+
56+
Recover middleware recovers from panics anywhere in the chain and handles the control
57+
to the centralized [HTTPErrorHandler](#error-handling).
58+
59+
*Example*
60+
61+
```go
62+
e.Use(mw.Recover())
63+
```
64+
65+
[Examples](https://github.com/labstack/echo/tree/master/examples/middleware)

website/content/guide/request.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Request
3+
menu:
4+
main:
5+
parent: guide
6+
---
7+
8+
### Path parameter
9+
10+
Path parameter can be retrieved either by name `Context.Param(name string) string`
11+
or by index `Context.P(i int) string`. Getting parameter by index gives a slightly
12+
better performance.
13+
14+
*Example*
15+
16+
```go
17+
e.Get("/users/:name", func(c *echo.Context) error {
18+
// By name
19+
name := c.Param("name")
20+
21+
// By index
22+
name := c.P(0)
23+
24+
return c.String(http.StatusOK, name)
25+
})
26+
```
27+
28+
```sh
29+
$ curl http://localhost:1323/users/joe
30+
```
31+
32+
### Query parameter
33+
34+
Query parameter can be retrieved by name using `Context.Query(name string)`.
35+
36+
*Example*
37+
38+
```go
39+
e.Get("/users", func(c *echo.Context) error {
40+
name := c.Query("name")
41+
return c.String(http.StatusOK, name)
42+
})
43+
```
44+
45+
```sh
46+
$ curl -G -d "name=joe" http://localhost:1323/users
47+
```
48+
49+
### Form parameter
50+
51+
Form parameter can be retrieved by name using `Context.Form(name string)`.
52+
53+
*Example*
54+
55+
```go
56+
e.Post("/users", func(c *echo.Context) error {
57+
name := c.Form("name")
58+
return c.String(http.StatusOK, name)
59+
})
60+
```
61+
62+
```sh
63+
$ curl -d "name=joe" http://localhost:1323/users
64+
```

0 commit comments

Comments
 (0)