The way to do this is to create a function in each that takes a route as a parameter, and then adds routes to the parameter:
package auth
import "...gin"
func Routes(route *gin.Engine)
auth := route.Group("/auth"){
auth.GET(...
auth.POST(...
}
...
package users
import "...gin"
func Routes(route *gin.Engine)
user := route.Group("/user"){
user.GET(...
user.POST(...
}
...
package main
import (
"github.com/username/package/sub/auth"
"github.com/username/package/sub/users"
"github.com/gin-gonic/gin"
)
...
router := gin.Default()
auth.Routes(router)
user.Routes(router)
router.Run()
...
source
share