From 332752efe69fb6215860b102a890430a85ad1ef1 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 7 Apr 2015 13:43:52 -0700 Subject: [PATCH] Fixed example/main.go Signed-off-by: Vishal Rana --- echo.go | 4 ++-- example/main.go | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/echo.go b/echo.go index 04d254d0e..94192469a 100644 --- a/echo.go +++ b/echo.go @@ -92,8 +92,8 @@ func New() (e *Echo) { func (h HandlerFunc) ServeHTTP(http.ResponseWriter, *http.Request) { } -// Group creates a sub router. It inherits all properties from the parent. -// Passing middleware overrides parent middleware. +// Group creates a new sub router with prefix and inherits all properties from +// the parent. Passing middleware overrides parent middleware. func (e *Echo) Group(pfx string, m ...Middleware) *Echo { g := *e g.prefix = pfx diff --git a/example/main.go b/example/main.go index fc4f0a22c..8efc7affc 100644 --- a/example/main.go +++ b/example/main.go @@ -80,23 +80,24 @@ func main() { e.Get("/users", getUsers) e.Get("/users/:id", getUser) - //****************// - // Sub router // - //****************// - // Sub - inherits parent middleware - sub := e.Sub("/sub") - sub.Use(func(c *echo.Context) { // Middleware + //***********// + // Group // + //***********// + // Group with parent middleware + a := e.Group("/admin") + a.Use(func(c *echo.Context) { + // Security middleware }) - sub.Get("/home", func(c *echo.Context) { - c.String(http.StatusOK, "Sub route /sub/welcome") + a.Get("", func(c *echo.Context) { + c.String(http.StatusOK, "Welcome admin!") }) - // Group - doesn't inherit parent middleware - grp := e.Group("/group") - grp.Use(func(c *echo.Context) { // Middleware + // Group with no parent middleware + g := e.Group("/files", func(c *echo.Context) { + // Security middleware }) - grp.Get("/home", func(c *echo.Context) { - c.String(http.StatusOK, "Group route /group/welcome") + g.Get("", func(c *echo.Context) { + c.String(http.StatusOK, "Your files!") }) // Start server