蛋蛋星球-客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

64 rindas
1.5 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/hdl/comm"
  6. "applet/app/mw"
  7. _ "applet/docs"
  8. "github.com/gin-gonic/gin"
  9. swaggerFiles "github.com/swaggo/files"
  10. ginSwagger "github.com/swaggo/gin-swagger"
  11. )
  12. // 初始化路由
  13. func Init() *gin.Engine {
  14. // debug, release, test 项目阶段
  15. mode := "release"
  16. if cfg.Debug {
  17. mode = "debug"
  18. }
  19. gin.SetMode(mode)
  20. //创建一个新的启动器
  21. r := gin.New()
  22. r.GET("/api/swagger/*any", func(c *gin.Context) {
  23. // r.Use(mw.SwagAuth())
  24. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  25. })
  26. // 是否打印访问日志, 在非正式环境都打印
  27. if mode != "release" {
  28. r.Use(gin.Logger())
  29. }
  30. r.Use(gin.Recovery())
  31. r.GET("/favicon.ico", func(c *gin.Context) {
  32. c.Status(204)
  33. })
  34. r.NoRoute(func(c *gin.Context) {
  35. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  36. })
  37. r.NoMethod(func(c *gin.Context) {
  38. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  39. })
  40. r.Use(mw.Cors)
  41. route(r.Group("/api/v1"))
  42. return r
  43. }
  44. func route(r *gin.RouterGroup) {
  45. r.GET("/test", hdl.Demo)
  46. r.Any("/createSign", hdl.CreateSign)
  47. r.Any("/aesDecryptByECB", hdl.AesDecryptByECB)
  48. r.Use(mw.CheckSign)
  49. r.Any("/testCreateSign", hdl.TestCreateSign)
  50. r.POST("/register", hdl.Register)
  51. r.POST("/login", hdl.Login)
  52. r.Use(mw.Auth) // 以下接口需要JWT验证
  53. rComm(r.Group("/comm"))
  54. }
  55. func rComm(r *gin.RouterGroup) {
  56. r.GET("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL
  57. }