app.Group(prefix) and register routes on the returned *Group value exactly as you would on the application.
Creating a group
*Group type exposes the same HTTP method shortcuts as *Application: Get, Post, Put, Patch, Delete, Head, Options, and AddRoute.
Adding middleware to a group
Callgroup.Use() to register middleware that runs only for routes in that group. Global middleware registered on the application still runs first.
GET /api/profile:
GET /ping) skips the group middleware entirely.
Nested groups
Callgroup.Group(prefix) to create a child group that inherits the parent’s prefix and middleware.
Complete example
The example below builds an/api/v1 group with authentication applied to all routes, and a nested /api/v1/admin group with an additional admin-only check.
GET /api/v1/users:
GET /api/v1/admin/stats:
Group middleware is cached after the first route registration on a group. Call
group.Use() before registering any routes to ensure all middleware is included.Using AddRoute on a group
When you need to register a route for a method determined at runtime, group.AddRoute works the same as app.AddRoute but prepends the group prefix and group middleware.