Skip to content

Commit 332752e

Browse files
committed
Fixed example/main.go
Signed-off-by: Vishal Rana <[email protected]>
1 parent a95d666 commit 332752e

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

echo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func New() (e *Echo) {
9292
func (h HandlerFunc) ServeHTTP(http.ResponseWriter, *http.Request) {
9393
}
9494

95-
// Group creates a sub router. It inherits all properties from the parent.
96-
// Passing middleware overrides parent middleware.
95+
// Group creates a new sub router with prefix and inherits all properties from
96+
// the parent. Passing middleware overrides parent middleware.
9797
func (e *Echo) Group(pfx string, m ...Middleware) *Echo {
9898
g := *e
9999
g.prefix = pfx

example/main.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,24 @@ func main() {
8080
e.Get("/users", getUsers)
8181
e.Get("/users/:id", getUser)
8282

83-
//****************//
84-
// Sub router //
85-
//****************//
86-
// Sub - inherits parent middleware
87-
sub := e.Sub("/sub")
88-
sub.Use(func(c *echo.Context) { // Middleware
83+
//***********//
84+
// Group //
85+
//***********//
86+
// Group with parent middleware
87+
a := e.Group("/admin")
88+
a.Use(func(c *echo.Context) {
89+
// Security middleware
8990
})
90-
sub.Get("/home", func(c *echo.Context) {
91-
c.String(http.StatusOK, "Sub route /sub/welcome")
91+
a.Get("", func(c *echo.Context) {
92+
c.String(http.StatusOK, "Welcome admin!")
9293
})
9394

94-
// Group - doesn't inherit parent middleware
95-
grp := e.Group("/group")
96-
grp.Use(func(c *echo.Context) { // Middleware
95+
// Group with no parent middleware
96+
g := e.Group("/files", func(c *echo.Context) {
97+
// Security middleware
9798
})
98-
grp.Get("/home", func(c *echo.Context) {
99-
c.String(http.StatusOK, "Group route /group/welcome")
99+
g.Get("", func(c *echo.Context) {
100+
c.String(http.StatusOK, "Your files!")
100101
})
101102

102103
// Start server

0 commit comments

Comments
 (0)