init_router.go 798 B

123456789101112131415161718192021222324252627282930313233343536
  1. package router
  2. import (
  3. "os"
  4. "github.com/gin-gonic/gin"
  5. log "github.com/go-admin-team/go-admin-core/logger"
  6. "github.com/go-admin-team/go-admin-core/sdk"
  7. common "go-admin/common/middleware"
  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 h.(type) {
  18. case *gin.Engine:
  19. r = h.(*gin.Engine)
  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. // TODO: 这里可存放业务路由,里边并无实际路由只有演示代码
  31. initRouter(r, authMiddleware)
  32. }