http.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/account-recovery/conf"
  5. "go-common/app/service/main/account-recovery/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. srv *service.Service
  13. vfy *verify.Verify
  14. authSvr *permit.Permit
  15. )
  16. // Init init
  17. func Init(c *conf.Config) {
  18. srv = service.New(c)
  19. vfy = verify.New(c.Verify)
  20. authSvr = permit.New(c.Auth)
  21. engine := bm.DefaultServer(c.BM)
  22. router(engine)
  23. if err := engine.Start(); err != nil {
  24. log.Error("engine.Start() error(%v)", err)
  25. panic(err)
  26. }
  27. }
  28. func router(e *bm.Engine) {
  29. e.Ping(ping)
  30. e.Register(register)
  31. g := e.Group("/x/account-recovery")
  32. {
  33. g.POST("/query", queryAccount)
  34. g.POST("/commit", commitInfo)
  35. g.POST("/getCaptchaMail", getCaptchaMail)
  36. g.GET("/captcha/token", webToken)
  37. g.POST("/captcha/verify", verifyCode)
  38. g.POST("/file/upload", bm.CORS(), fileUpload)
  39. }
  40. adminGroup := e.Group("/x/admin/account-recovery", authSvr.Permit("ACCOUNT_RECOVERY_NORMAL"))
  41. {
  42. adminGroup.GET("/queryCon", queryConWithBusiness(""))
  43. adminGroup.GET("/queryCon/account", authSvr.Permit("ACCOUNT_RECOVERY_ACCOUNT"), queryConWithBusiness("account"))
  44. adminGroup.GET("/queryCon/game", authSvr.Permit("ACCOUNT_RECOVERY_GAME"), queryConWithBusiness("game"))
  45. // todo judge,batchJudge也需要分配权限
  46. adminGroup.POST("/judge", judge)
  47. adminGroup.POST("/batchJudge", batchJudge)
  48. adminGroup.POST("/gameList", gameList)
  49. }
  50. internalGroup := e.Group("/x/internal/account-recovery", vfy.Verify)
  51. {
  52. internalGroup.POST("/compare", compareInfo)
  53. internalGroup.POST("/sendMail", sendMail)
  54. }
  55. }
  56. func ping(c *bm.Context) {
  57. if err := srv.Ping(c); err != nil {
  58. log.Error("ping error(%v)", err)
  59. c.AbortWithStatus(http.StatusServiceUnavailable)
  60. }
  61. }
  62. func register(c *bm.Context) {
  63. c.JSON(map[string]interface{}{}, nil)
  64. }