golang 的 rabbitmq 消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

router.go 861 B

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/mw"
  5. _ "applet/docs"
  6. "github.com/gin-gonic/gin"
  7. )
  8. //初始化路由
  9. func Init() *gin.Engine {
  10. // debug, release, test 项目阶段
  11. mode := "release"
  12. if cfg.Debug {
  13. mode = "debug"
  14. }
  15. gin.SetMode(mode)
  16. //创建一个新的启动器
  17. r := gin.New()
  18. r.Use(mw.ChangeHeader)
  19. // 是否打印访问日志, 在非正式环境都打印
  20. if mode != "release" {
  21. r.Use(gin.Logger())
  22. }
  23. r.Use(gin.Recovery())
  24. // r.Use(mw.Limiter)
  25. //r.LoadHTMLGlob("static/html/*")
  26. r.GET("/favicon.ico", func(c *gin.Context) {
  27. c.Status(204)
  28. })
  29. r.NoRoute(func(c *gin.Context) {
  30. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  31. })
  32. r.NoMethod(func(c *gin.Context) {
  33. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  34. })
  35. r.Use(mw.Cors)
  36. return r
  37. }