Skip to content

Commit

Permalink
Fixed example/main.go
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Apr 7, 2015
1 parent a95d666 commit 332752e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 332752e

Please sign in to comment.