File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -92,8 +92,8 @@ func New() (e *Echo) {
92
92
func (h HandlerFunc ) ServeHTTP (http.ResponseWriter , * http.Request ) {
93
93
}
94
94
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.
97
97
func (e * Echo ) Group (pfx string , m ... Middleware ) * Echo {
98
98
g := * e
99
99
g .prefix = pfx
Original file line number Diff line number Diff line change @@ -80,23 +80,24 @@ func main() {
80
80
e .Get ("/users" , getUsers )
81
81
e .Get ("/users/:id" , getUser )
82
82
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
89
90
})
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! " )
92
93
})
93
94
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
97
98
})
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! " )
100
101
})
101
102
102
103
// Start server
You can’t perform that action at this time.
0 commit comments