1
0
mirror of https://github.com/labstack/echo.git synced 2025-06-19 00:27:34 +02:00

Putting func(http.Handler) http.Handler middleware back

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-04-20 23:17:21 -07:00
parent f00e11010b
commit 2e5d09d225
5 changed files with 47 additions and 15 deletions

View File

@ -7,6 +7,8 @@ import (
"html/template"
"github.com/labstack/echo"
"github.com/rs/cors"
"github.com/thoas/stats"
)
type (
@ -57,6 +59,21 @@ func main() {
// Middleware
e.Use(echo.Logger)
//------------------------
// Third-party middleware
//------------------------
// https://github.com/rs/cors
e.Use(cors.Default().Handler)
// https://github.com/thoas/stats
s := stats.New()
e.Use(s.Handler)
// Route
e.Get("/stats", func(c *echo.Context) {
c.JSON(http.StatusOK, s.Data())
})
// Serve index file
e.Index("public/index.html")
@ -66,6 +83,7 @@ func main() {
//--------
// Routes
//--------
e.Post("/users", createUser)
e.Get("/users", getUsers)
e.Get("/users/:id", getUser)
@ -73,6 +91,7 @@ func main() {
//-----------
// Templates
//-----------
t := &Template{
// Cached templates
templates: template.Must(template.ParseFiles("public/views/welcome.html")),