init_router.go 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package router
  2. import (
  3. "os"
  4. common "go-admin/common/middleware"
  5. "github.com/gin-gonic/gin"
  6. log "github.com/go-admin-team/go-admin-core/logger"
  7. "github.com/go-admin-team/go-admin-core/sdk"
  8. )
  9. // InitRouter 路由初始化,不要怀疑,这里用到了
  10. func InitRouter() {
  11. var r *gin.Engine
  12. h := sdk.Runtime.GetEngine()
  13. if h == nil {
  14. log.Fatal("not found engine...")
  15. os.Exit(-1)
  16. }
  17. switch t := h.(type) {
  18. case *gin.Engine:
  19. r = t
  20. default:
  21. log.Fatal("not support other engine")
  22. os.Exit(-1)
  23. }
  24. // the jwt middleware
  25. authMiddleware, err := common.AuthInit()
  26. if err != nil {
  27. log.Fatalf("JWT Init Error, %s", err.Error())
  28. }
  29. // 注册系统路由
  30. InitSysRouter(r, authMiddleware)
  31. // 注册业务路由
  32. // TODO: 这里可存放业务路由,里边并无实际路由只有演示代码
  33. InitExamplesRouter(r, authMiddleware)
  34. }