数据采集
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 845 B

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