1
0
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:
Vishal Rana 2015-06-07 19:57:49 -07:00
parent 302e85a5ae
commit 0edb31b3bd
7 changed files with 197 additions and 12 deletions

View File

@ -30,8 +30,8 @@ func main() {
e.Use(mw.Recover())
// Basic auth
e.Use(mw.BasicAuth(func(u, p string) bool {
if u == "joe" && p == "secret" {
e.Use(mw.BasicAuth(func(usr, pwd string) bool {
if usr == "joe" && pwd == "secret" {
return true
}
return false

View File

@ -9,7 +9,7 @@ import (
)
// Recover returns a middleware which recovers from panics anywhere in the chain
// and handles the control to centralized HTTPErrorHandler.
// and handles the control to the centralized HTTPErrorHandler.
func Recover() echo.MiddlewareFunc {
// TODO: Provide better stack trace `https://github.com/go-errors/errors` `https://github.com/docker/libcontainer/tree/master/stacktrace`
return func(h echo.HandlerFunc) echo.HandlerFunc {

View File

@ -59,7 +59,7 @@ code below registers a route for method `GET`, path `/hello` and a handler which
`Hello!` HTTP response.
```go
echo.Get("/hello", func(*echo.Context) error {
echo.Get("/hello", func(c *echo.Context) error {
return c.String(http.StatusOK, "Hello!")
})
```
@ -68,11 +68,27 @@ Echo's default handler is `func(*echo.Context) error` where `echo.Context`
primarily holds HTTP request and response objects. Echo also has a support for other
types of handlers.
<!-- TODO mention about not able to take advantage -->
### Group
*WIP*
`Echo.Group(prefix string, m ...Middleware) *Group`
Routes with common prefix can be grouped to define a new sub-router with optional
middleware. If middleware is passed to the function, it overrides parent middleware
- helpful if you want a completly new middleware stack for the group. To add middleware
later you can use `Group.Use(m ...Middleware)`. Groups can also be nested.
In the code below, we create an admin group which requires basic HTTP authentication
for routes `/admin/*`.
```go
echo.Group("/admin")
e.Use(mw.BasicAuth(func(usr, pwd string) bool {
if usr == "joe" && pwd == "secret" {
return true
}
return false
}))
```
### Path parameter
@ -154,7 +170,93 @@ e.Get("/users/:id", h)
## Middleware
[*WIP*](https://github.com/labstack/echo/tree/master/examples/middleware)
Middleware is function which is chained in the HTTP request-response cycle. Middleware
has access to the request and response objects which it utilizes to perform a specific
action for example, logging every request. Echo supports variety of [middleware](/#features).
### Logger
Logs each HTTP request with method, path, status, response time and bytes served.
*Example*
```go
e.Use(Logger())
// Output: `2015/06/07 18:16:16 GET / 200 13.238µs 14`
```
### BasicAuth
BasicAuth middleware provides an HTTP basic authentication.
- For valid credentials it calls the next handler in the chain.
- For invalid Authorization header it sends "404 - Bad Request" response.
- For invalid credentials, it sends "401 - Unauthorized" response.
*Example*
```go
echo.Group("/admin")
e.Use(mw.BasicAuth(func(usr, pwd string) bool {
if usr == "joe" && pwd == "secret" {
return true
}
return false
}))
```
### Gzip
Gzip middleware compresses HTTP response using gzip compression scheme.
*Example*
```go
e.Use(mw.Gzip())
```
### Recover
Recover middleware recovers from panics anywhere in the chain and handles the control
to the centralized [HTTPErrorHandler](#error-handling).
*Example*
```go
e.Use(mw.Recover())
```
### StripTrailingSlash
StripTrailingSlash middleware removes the trailing slash from request path.
*Example*
```go
e.Use(mw.StripTrailingSlash())
```
### RedirectToSlash
RedirectToSlash middleware redirects requests without trailing slash path to trailing
slash path.
*Options*
```go
RedirectToSlashOptions struct {
Code int
}
```
*Example*
```go
e.Use(mw.RedirectToSlash())
```
*Note*: StripTrailingSlash and RedirectToSlash should not be used together.
[Examples](https://github.com/labstack/echo/tree/master/examples/middleware)
## Response

View File

@ -86,9 +86,7 @@ func main() {
made to the server, producing output
```sh
2015/04/25 12:15:20 GET / 200 7.544µs
2015/04/25 12:15:26 GET / 200 3.681µs
2015/04/25 12:15:29 GET / 200 5.434µs
2015/06/07 18:16:16 GET / 200 13.238µs 14
```
`e.Get("/", hello)` Registers hello handler for HTTP method `GET` and path `/`, so

78
website/echo/base.html Normal file
View File

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if page_description %}<meta name="description" content="{{ page_description }}">{% endif %}
{% if site_author %}<meta name="author" content="{{ site_author }}">{% endif %}
{% if canonical_url %}<link rel="canonical" href="{{ canonical_url }}">{% endif %}
{% if favicon %}<link rel="shortcut icon" href="{{ favicon }}">
{% else %}<link rel="shortcut icon" href="{{ base_url }}/img/favicon.ico">{% endif %}
<title>{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}</title>
<link href="{{ base_url }}/css/bootstrap-custom.min.css" rel="stylesheet">
<link href="{{ base_url }}/css/font-awesome-4.0.3.css" rel="stylesheet">
<link rel="stylesheet" href="{{ base_url }}/css/highlight.css">
<link href="{{ base_url }}/css/base.css" rel="stylesheet">
<link href="{{ base_url }}/css/echo.css" rel="stylesheet">
{%- for path in extra_css %}
<link href="{{ path }}" rel="stylesheet">
{%- endfor %}
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
{% if google_analytics %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{{ google_analytics[0] }}', '{{ google_analytics[1] }}');
ga('send', 'pageview');
</script>
{% endif %}
</head>
<body>
{% include "nav.html" %}
<div class="container">
<div class="col-md-3">{% include "toc.html" %}</div>
<div class="col-md-9" role="main">{% include "content.html" %}</div>
</div>
<footer class="col-md-12">
<hr>
<center class="social">
<a href="https://github.com/labstack" target="_blank">
<i class="fa fa-github fa-2x"></i>
</a>
<a href="https://twitter.com/labstack" target="_blank">
<i class="fa fa-twitter fa-2x"></i>
</a>
<a href="https://www.facebook.com/labstack" target="_blank">
<i class="fa fa-facebook fa-2x"></i>
</a>
</center>
{% if copyright %}
<center>{{ copyright }}</center>
{% endif %}
</footer>
<script src="{{ base_url }}/js/jquery-1.10.2.min.js"></script>
<script src="{{ base_url }}/js/bootstrap-3.0.3.min.js"></script>
<script src="{{ base_url }}/js/highlight.pack.js"></script>
<script src="{{ base_url }}/js/base.js"></script>
{%- for path in extra_javascript %}
<script src="{{ path }}"></script>
{%- endfor %}
</body>
</html>

View File

@ -0,0 +1,3 @@
.social a {
text-decoration: none;
}

View File

@ -1,6 +1,10 @@
site_name: Echo
theme: flatly
theme: journal
theme_dir: echo
copyright: © 2015 LabStack
repo_url: https://github.com/labstack/echo