2015-04-19 22:04:30 -07:00
|
|
|
# Echo
|
|
|
|
|
2015-07-01 21:22:51 -07:00
|
|
|
A fast and unfancy micro web framework for Golang.
|
2015-04-19 22:04:30 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2015-04-18 21:53:38 -07:00
|
|
|
## Features
|
|
|
|
|
2015-06-18 14:40:48 -07:00
|
|
|
- Fast HTTP router which smartly prioritize routes.
|
2015-06-03 09:20:32 -07:00
|
|
|
- Extensible middleware, supports:
|
|
|
|
- `echo.MiddlewareFunc`
|
|
|
|
- `func(echo.HandlerFunc) echo.HandlerFunc`
|
|
|
|
- `echo.HandlerFunc`
|
|
|
|
- `func(*echo.Context) error`
|
|
|
|
- `func(http.Handler) http.Handler`
|
|
|
|
- `http.Handler`
|
|
|
|
- `http.HandlerFunc`
|
|
|
|
- `func(http.ResponseWriter, *http.Request)`
|
|
|
|
- Extensible handler, supports:
|
|
|
|
- `echo.HandlerFunc`
|
|
|
|
- `func(*echo.Context) error`
|
|
|
|
- `http.Handler`
|
|
|
|
- `http.HandlerFunc`
|
|
|
|
- `func(http.ResponseWriter, *http.Request)`
|
2015-06-18 14:40:48 -07:00
|
|
|
- Sub-router/Groups
|
2015-07-08 13:51:08 -07:00
|
|
|
- Handy functions to send variety of HTTP response:
|
|
|
|
- HTML
|
|
|
|
- HTML via templates
|
|
|
|
- String
|
2015-07-11 15:20:59 -04:00
|
|
|
- JSON
|
|
|
|
- XML
|
2015-07-08 13:51:08 -07:00
|
|
|
- NoContent
|
|
|
|
- Redirect
|
|
|
|
- Error
|
2015-06-03 09:20:32 -07:00
|
|
|
- Build-in support for:
|
2015-07-08 13:51:08 -07:00
|
|
|
- Favicon
|
|
|
|
- Index file
|
2015-06-18 14:40:48 -07:00
|
|
|
- Static files
|
|
|
|
- WebSocket
|
|
|
|
- Centralized HTTP error handling.
|
2015-07-08 13:51:08 -07:00
|
|
|
- Customizable HTTP request binding function.
|
|
|
|
- Customizable HTTP response rendering function, allowing you to use any HTML template engine.
|
2015-04-18 21:53:38 -07:00
|
|
|
|
2015-06-22 14:25:39 -07:00
|
|
|
## Performance
|
|
|
|
|
2015-06-27 23:34:22 +02:00
|
|
|
<iframe width="600" height="371" seamless frameborder="0" scrolling="no" src="https://docs.google.com/spreadsheets/d/1phsG_NPmEOaTVTw6lasK3CeEwBlbkhzAWPiyrBznm1g/pubchart?oid=178095723&format=interactive"></iframe>
|
2015-06-22 14:25:39 -07:00
|
|
|
|
2015-04-24 15:13:06 -07:00
|
|
|
## Getting Started
|
2015-04-18 21:53:38 -07:00
|
|
|
|
2015-04-24 15:13:06 -07:00
|
|
|
### Installation
|
|
|
|
|
2015-04-25 12:46:27 -07:00
|
|
|
```sh
|
|
|
|
$ go get github.com/labstack/echo
|
|
|
|
```
|
2015-04-18 21:53:38 -07:00
|
|
|
|
2015-07-01 21:22:51 -07:00
|
|
|
### Hello, World!
|
2015-04-19 22:47:58 -07:00
|
|
|
|
2015-07-08 13:51:08 -07:00
|
|
|
Create `server.go`
|
2015-04-18 21:53:38 -07:00
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
2015-04-20 23:24:34 -07:00
|
|
|
mw "github.com/labstack/echo/middleware"
|
2015-04-18 21:53:38 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler
|
2015-05-20 15:59:36 -07:00
|
|
|
func hello(c *echo.Context) error {
|
2015-05-05 21:55:49 -07:00
|
|
|
return c.String(http.StatusOK, "Hello, World!\n")
|
2015-04-18 21:53:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2015-04-25 12:46:27 -07:00
|
|
|
// Echo instance
|
2015-04-18 21:53:38 -07:00
|
|
|
e := echo.New()
|
|
|
|
|
|
|
|
// Middleware
|
2015-05-15 12:29:14 -07:00
|
|
|
e.Use(mw.Logger())
|
2015-05-18 11:33:11 -07:00
|
|
|
e.Use(mw.Recover())
|
2015-04-18 21:53:38 -07:00
|
|
|
|
|
|
|
// Routes
|
|
|
|
e.Get("/", hello)
|
|
|
|
|
|
|
|
// Start server
|
2015-05-10 08:22:49 -07:00
|
|
|
e.Run(":1323")
|
2015-04-18 21:53:38 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-07-08 13:51:08 -07:00
|
|
|
Start server
|
2015-04-18 21:53:38 -07:00
|
|
|
|
2015-04-25 12:46:27 -07:00
|
|
|
```sh
|
|
|
|
$ go run server.go
|
2015-04-18 21:53:38 -07:00
|
|
|
```
|
2015-04-18 22:27:30 -07:00
|
|
|
|
2015-05-10 08:22:49 -07:00
|
|
|
Browse to [http://localhost:1323](http://localhost:1323) and you should see
|
2015-04-25 12:46:27 -07:00
|
|
|
Hello, World! on the page.
|
|
|
|
|
2015-04-25 16:10:28 -07:00
|
|
|
### Next?
|
2015-06-30 12:10:35 -07:00
|
|
|
- Browse [recipes](https://github.com/labstack/echo/tree/master/recipes)
|
2015-04-25 16:10:28 -07:00
|
|
|
- Head over to [Guide](guide.md)
|
|
|
|
|
2015-04-19 22:04:30 -07:00
|
|
|
## Contribute
|
2015-04-25 12:46:27 -07:00
|
|
|
|
|
|
|
**Use issues for everything**
|
2015-04-26 22:41:41 -07:00
|
|
|
|
2015-04-29 13:54:47 -07:00
|
|
|
- Report issues
|
2015-04-25 12:46:27 -07:00
|
|
|
- Discuss before sending pull request
|
2015-04-19 22:04:30 -07:00
|
|
|
- Suggest new features
|
2015-04-25 12:46:27 -07:00
|
|
|
- Improve/fix documentation
|
2015-04-19 22:04:30 -07:00
|
|
|
|
2015-04-25 16:10:28 -07:00
|
|
|
## Credits
|
|
|
|
- [Vishal Rana](https://github.com/vishr) - Author
|
|
|
|
- [Nitin Rana](https://github.com/nr17) - Consultant
|
|
|
|
- [Contributors](https://github.com/labstack/echo/graphs/contributors)
|
|
|
|
|
2015-04-18 22:27:30 -07:00
|
|
|
## License
|
|
|
|
|
|
|
|
[MIT](https://github.com/labstack/echo/blob/master/LICENSE)
|