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) {
9292func (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.
9797func (e * Echo ) Group (pfx string , m ... Middleware ) * Echo {
9898 g := * e
9999 g .prefix = pfx
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments