Route Groups

Organize routes that share common attributes.


Grouping Routes

Route groups allow you to share route attributes, such as middleware or URL prefixes, across a large number of routes without needing to define those attributes on each individual route.

// API Version 1 Group
v1 := r.Group("/api/v1")
{
    v1.GET("/users", GetUsers)
    v1.POST("/users", CreateUser)
}

// Protected Admin Group
admin := r.Group("/admin")
admin.Use(AuthMiddleware)
{
    admin.GET("/dashboard", AdminDashboard)
    admin.GET("/settings", AdminSettings)
}