http.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/usersuit/conf"
  5. "go-common/app/service/main/usersuit/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. usersuitSvc *service.Service
  12. vfySvc *verify.Verify
  13. )
  14. // Init init http sever instance.
  15. func Init(c *conf.Config, s *service.Service) {
  16. usersuitSvc = s
  17. vfySvc = verify.New(c.Verify)
  18. // init inner router
  19. innerEngine := bm.DefaultServer(c.BM)
  20. innerRouter(innerEngine)
  21. // init inner server
  22. if err := innerEngine.Start(); err != nil {
  23. log.Error("xhttp.Serve inner error(%v)", err)
  24. panic(err)
  25. }
  26. }
  27. // innerRouter init inner router.
  28. func innerRouter(e *bm.Engine) {
  29. // health check
  30. e.Ping(ping)
  31. e.Register(register)
  32. group := e.Group("/x/internal/pendant", vfySvc.Verify)
  33. {
  34. group.GET("/groupInfo", groupInfo)
  35. group.GET("/groupInfoByID", groupInfoByID)
  36. group.GET("/pendantByID", pendantByID)
  37. group.GET("/vipGroup", vipGroup)
  38. group.GET("/entryGroup", entryGroup)
  39. group.GET("/pointRecommend", pointRecommend)
  40. group.GET("/package", packageInfo)
  41. group.GET("/equipment", equipment)
  42. group.GET("/orderHistory", orderHistory)
  43. group.POST("/order", order)
  44. group.POST("/equip", equip)
  45. group.POST("/multiGrantByMid", multiGrantByMid)
  46. group.POST("/multiGrantByPid", multiGrantByPid)
  47. }
  48. e.POST("/x/internal/pendant/callback", pendantCallback)
  49. medal := e.Group("/x/internal/medal", vfySvc.Verify)
  50. {
  51. medal.GET("/my", medalMy)
  52. medal.GET("/all", medalAllInfo)
  53. medal.GET("/info", medalInfo)
  54. medal.GET("/popup", medalPopup)
  55. medal.GET("/user", medalUser)
  56. medal.GET("/check", medalCheck)
  57. medal.GET("/activated", medalActivated)
  58. medal.POST("/install", medalInstall)
  59. medal.POST("/grant", medalGet)
  60. }
  61. }
  62. // ping check server ok.
  63. func ping(c *bm.Context) {
  64. if err := usersuitSvc.Ping(c); err != nil {
  65. log.Error("usersuit-service service ping error (%+v)", err)
  66. c.AbortWithStatus(http.StatusServiceUnavailable)
  67. }
  68. }
  69. // register check server ok.
  70. func register(c *bm.Context) {
  71. c.JSON(map[string]interface{}{}, nil)
  72. }