router.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package router
  2. import (
  3. "net/http"
  4. "github.com/gin-contrib/gzip"
  5. "github.com/gin-contrib/sessions"
  6. "github.com/gin-contrib/sessions/cookie"
  7. "github.com/gin-gonic/gin"
  8. "nn.daxia.dev/handler/api"
  9. "nn.daxia.dev/handler/common"
  10. "nn.daxia.dev/router/middleware"
  11. )
  12. // 载入中间件
  13. func Load(g *gin.Engine, mw ...gin.HandlerFunc) *gin.Engine {
  14. store := cookie.NewStore([]byte("gamee-389aec83c8f9"))
  15. g.Use(gin.Logger())
  16. g.Use(gin.Recovery())
  17. g.Use(gzip.Gzip(gzip.DefaultCompression))
  18. g.Use(middleware.GlobalError())
  19. g.Use(middleware.NoCache())
  20. g.Use(middleware.Options())
  21. g.Use(middleware.Secure())
  22. g.Use(sessions.Sessions("default", store))
  23. g.Use(mw...)
  24. g.NoRoute(func(ctx *gin.Context) {
  25. ctx.String(http.StatusNotFound, "incorrect api router")
  26. })
  27. g.GET("/connect", gin.WrapF(Index))
  28. checkRoute := g.Group("/check")
  29. {
  30. checkRoute.GET("/ping", func(ctx *gin.Context) {
  31. ctx.String(http.StatusOK, "ping")
  32. })
  33. }
  34. ntApiRoute := g.Group("/api/nt")
  35. {
  36. ntApiRoute.POST("notify", api.Notify) //通知接口
  37. }
  38. //内部通讯业务
  39. bsApiRoute := g.Group("/api/bs")
  40. {
  41. bsApiRoute.POST("/perform", common.Dispatch)
  42. // gameQZNNApi := bsApiRoute.Group("/qznn")
  43. // {
  44. // gameQZNNApi.POST("ready", game.QznnReady)
  45. // gameQZNNApi.POST("choose_master", game.QznnChooseMaster)
  46. // gameQZNNApi.POST("choose_mul", game.QznnChooseMul)
  47. // gameQZNNApi.POST("open", game.QznnOpen)
  48. // }
  49. }
  50. return g
  51. }