init.go 458 B

12345678910111213141516171819202122
  1. package router
  2. import (
  3. "github.com/gin-gonic/gin"
  4. )
  5. // 路由配置函数类型
  6. type RouteSetupFunc func(*gin.Engine)
  7. var routeRegistrations []RouteSetupFunc
  8. // 注册路由配置(自动被各个路由文件调用)
  9. func RegisterRoute(setup RouteSetupFunc) {
  10. routeRegistrations = append(routeRegistrations, setup)
  11. }
  12. // 统一设置路由入口
  13. func SetupRoutes(engine *gin.Engine) {
  14. for _, setup := range routeRegistrations {
  15. setup(engine)
  16. }
  17. }