Group Routes in Gin

Group Routes in Gin

We can Group Gin Routes under a common route prefix like /api/v1/ or /api/v2/

func main() {
    router := gin.Default()

    // /api/v1/login
    // /api/v1/users
	v1 := router.Group("/api/v1")
	{
		v1.POST("/login", oldLoginHandler)
		v1.GET("/users", oldUsersHandler)
	}

    // /api/v2/login
    // /api/v2/users
	v2 := router.Group("/api/v2")
	{
		v2.POST("/login", newLoginHandler)
		v2.GET("/users", newUsersHandler)
	}
    

    router.Run(":8080")
}

All Grouped Routes under this would be,

Last updated on