router.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package router
  2. import (
  3. "gmanager/app/api/common"
  4. "gmanager/app/api/config"
  5. "gmanager/app/api/department"
  6. "gmanager/app/api/game"
  7. "gmanager/app/api/gm"
  8. "gmanager/app/api/log"
  9. "gmanager/app/api/menu"
  10. "gmanager/app/api/role"
  11. "gmanager/app/api/user"
  12. "gmanager/app/component/middle"
  13. "gmanager/app/component/started"
  14. "gmanager/app/constants"
  15. "gmanager/library/base"
  16. "strings"
  17. "github.com/goflyfox/gtoken/gtoken"
  18. "github.com/gogf/gf/frame/g"
  19. "github.com/gogf/gf/net/ghttp"
  20. "github.com/gogf/gf/os/glog"
  21. )
  22. /*
  23. 绑定业务路由
  24. */
  25. func bindRouter() {
  26. urlPath := g.Config().GetString("url-path")
  27. s := g.Server()
  28. // 中间件
  29. // 允许跨域
  30. s.BindMiddleware("/*", func(r *ghttp.Request) {
  31. r.Response.CORSDefault()
  32. r.Middleware.Next()
  33. })
  34. // 日志拦截
  35. s.BindMiddleware(urlPath+"/*", middle.MiddlewareLog)
  36. // 通用属性
  37. s.BindMiddleware(urlPath+"/*", middle.MiddlewareCommon)
  38. // 首页
  39. s.BindHandler(urlPath+"/", common.Login)
  40. s.BindHandler(urlPath+"/main.html", common.Index)
  41. s.BindHandler(urlPath+"/login", common.Login)
  42. s.BindHandler(urlPath+"/welcome", common.Welcome)
  43. s.BindHandler(urlPath+"/admin/welcome.html", common.Welcome)
  44. s.BindHandler("/SendGM", common.GM)
  45. s.BindHandler("/SendMail", common.SendMail)
  46. gmAction:=new(gm.Action)
  47. //group.ALL("gm", gmAction)
  48. s.BindHandler("/gm/downloadcdk/{ticke}", gmAction.DownloadCdk)
  49. s.Group(urlPath+"/system", func(group *ghttp.RouterGroup) {
  50. userAction := new(user.Action)
  51. group.ALL("user", userAction)
  52. group.GET("/user/get/{id}", userAction.Get)
  53. group.ALL("user/delete/{id}", userAction.Delete)
  54. departAction := new(department.Action)
  55. group.ALL("department", departAction)
  56. group.GET("/department/get/{id}", departAction.Get)
  57. group.ALL("/department/delete/{id}", departAction.Delete)
  58. logAction := new(log.Action)
  59. group.ALL("log", logAction)
  60. group.GET("/log/get/{id}", logAction.Get)
  61. group.ALL("/log/delete/{id}", logAction.Delete)
  62. menuAction := new(menu.Action)
  63. group.ALL("menu", menuAction)
  64. group.GET("/menu/get/{id}", menuAction.Get)
  65. group.ALL("/menu/delete/{id}", menuAction.Delete)
  66. roleAction := new(role.Action)
  67. group.ALL("role", roleAction)
  68. group.GET("/role/get/{id}", roleAction.Get)
  69. group.ALL("/role/delete/{id}", roleAction.Delete)
  70. configAction := new(config.Action)
  71. group.ALL("config", configAction)
  72. group.GET("/config/get/{id}", configAction.Get)
  73. group.ALL("/config/delete/{id}", configAction.Delete)
  74. gameAction := new(game.Action)
  75. group.ALL("game", gameAction)
  76. group.GET("/game/getserverdetail/{id}", gameAction.GetServerDetail)
  77. group.ALL("/game/delserver/{id}", gameAction.DelServer)
  78. group.GET("/game/getwhitelistdetail/{id}", gameAction.GetWhiteListDetail)
  79. group.ALL("/game/delwhitelist/{id}", gameAction.DelWhiteList)
  80. group.GET("/game/getblacklistdetail/{id}", gameAction.GetBlackListDetail)
  81. group.ALL("/game/delblacklist/{id}", gameAction.DelBlackList)
  82. group.GET("/game/getnoticeinfodetail/{id}", gameAction.GetNoticeInfoDetail)
  83. group.ALL("/game/delnoticeinfo/{id}", gameAction.DelNoticeInfo)
  84. group.GET("/game/setsilence/{id}", gameAction.SetSilence)
  85. gmAction := new(gm.Action)
  86. //group.ALL("/gm/sendmail", gmAction.SendMail)
  87. group.ALL("gm", gmAction)
  88. //group.ALL("/gm/downloadcdk/{cdkid}", gmAction.DownloadCdk)
  89. //group.GET("/gm/get/{id}", gmAction.Get)
  90. //group.ALL("/gm/delete/{id}", gmAction.Delete)
  91. })
  92. // 启动gtoken
  93. base.Token = &gtoken.GfToken{
  94. //Timeout: 10 * 1000,
  95. CacheMode: g.Config().GetInt8("gtoken.cache-mode"),
  96. MultiLogin: g.Config().GetBool("gtoken.multi-login"),
  97. LoginPath: urlPath + "/login/submit",
  98. LoginBeforeFunc: common.LoginSubmit,
  99. LogoutPath: urlPath + "/user/logout",
  100. LogoutBeforeFunc: common.LogoutBefore,
  101. AuthPaths: g.SliceStr{"/user", "/system"},
  102. GlobalMiddleware: true,
  103. AuthBeforeFunc: func(r *ghttp.Request) bool {
  104. // 静态页面不拦截
  105. if r.IsFileRequest() {
  106. return false
  107. }
  108. if strings.HasSuffix(r.URL.Path, "index") {
  109. return false
  110. }
  111. return true
  112. },
  113. }
  114. base.Token.Start()
  115. }
  116. /*
  117. 统一路由注册
  118. */
  119. func init() {
  120. glog.Info("########router start...")
  121. s := g.Server()
  122. // 绑定路由
  123. bindRouter()
  124. if constants.DEBUG {
  125. g.DB().SetDebug(constants.DEBUG)
  126. }
  127. // 上线建议关闭
  128. s.BindHandler("/debug", common.Debug)
  129. // 301错误页面
  130. s.BindStatusHandler(301, common.Error301)
  131. // 404错误页面
  132. s.BindStatusHandler(404, common.Error404)
  133. // 500错误页面
  134. s.BindStatusHandler(500, common.Error500)
  135. // 某些浏览器直接请求favicon.ico文件,特别是产生404时
  136. s.SetRewrite("/favicon.ico", "/resources/images/favicon.ico")
  137. // 管理接口
  138. s.EnableAdmin("/admin")
  139. // 为平滑重启管理页面设置HTTP Basic账号密码
  140. //s.BindHookHandler("/admin/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
  141. // user := g.Config().GetString("admin.user")
  142. // pass := g.Config().GetString("admin.pass")
  143. // if !r.BasicAuth(user, pass) {
  144. // r.ExitAll()
  145. // }
  146. //})
  147. // 强制跳转到HTTPS访问
  148. //g.Server().BindHookHandler("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
  149. // if !r.IsFileServe() && r.TLS == nil {
  150. // r.Response.RedirectTo(fmt.Sprintf("https://%s%s", r.Host, r.URL.String()))
  151. // r.ExitAll()
  152. // }
  153. //})
  154. started.StartLog()
  155. glog.Info("########router finish.")
  156. }