http.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/spy/conf"
  5. "go-common/app/admin/main/spy/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. spySrv *service.Service
  12. vfySvc *verify.Verify
  13. )
  14. // Init init http sever instance.
  15. func Init(c *conf.Config) {
  16. initService(c)
  17. // init inner router
  18. engine := bm.DefaultServer(c.HTTPServer)
  19. innerRouter(engine)
  20. // init inner server
  21. if err := engine.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // innerRouter init inner router.
  27. func innerRouter(e *bm.Engine) {
  28. // health check
  29. e.Ping(ping)
  30. spy := e.Group("/x/admin/spy", vfySvc.Verify)
  31. score := spy.Group("/score")
  32. score.GET("/query", userInfo)
  33. score.GET("/record", historyPage)
  34. score.POST("/base/reset", resetBase)
  35. score.POST("/base/refresh", refreshBase)
  36. score.POST("/event/reset", resetEvent)
  37. spy.POST("/stat/clear", clearCount)
  38. factor := spy.Group("/factor")
  39. factor.GET("/list", factors)
  40. factor.POST("/add", addFactor)
  41. factor.POST("/modify", updateFactor)
  42. spy.POST("/event/add", addEvent)
  43. spy.POST("/event/modify", updateEventName)
  44. spy.POST("/service/add", addService)
  45. spy.POST("/group/add", addGroup)
  46. setting := spy.Group("/setting")
  47. setting.GET("/list", settingList)
  48. setting.POST("/add", updateSetting)
  49. sin := spy.Group("/sin")
  50. sin.POST("/state/update", updateStatState)
  51. sin.POST("/quantity/update", updateStatQuantity)
  52. sin.POST("/delete", deleteStat)
  53. sin.POST("/remark/add", addRemark)
  54. sin.GET("/remark/list", remarkList)
  55. sin.GET("/page", statPage)
  56. spy.GET("/report", report)
  57. spyWithoutAuth := e.Group("/x/admin/spy/internal")
  58. spyWithoutAuth.POST("/event/add", addEvent)
  59. spyWithoutAuth.POST("/event/modify", updateEventName)
  60. scoreWithoutAuth := spyWithoutAuth.Group("/score")
  61. scoreWithoutAuth.GET("/query", userInfo)
  62. scoreWithoutAuth.GET("/record", historyPage)
  63. scoreWithoutAuth.POST("/base/reset", resetBase)
  64. scoreWithoutAuth.POST("/base/refresh", refreshBase)
  65. scoreWithoutAuth.POST("/event/reset", resetEvent)
  66. factorWithoutAuth := spyWithoutAuth.Group("/factor")
  67. factorWithoutAuth.GET("/list", factors)
  68. factorWithoutAuth.POST("/add", addFactor)
  69. factorWithoutAuth.POST("/modify", updateFactor)
  70. }
  71. // ping check server ok.
  72. func ping(c *bm.Context) {
  73. if err := spySrv.Ping(c); err != nil {
  74. log.Error("spy admin ping error(%v)", err)
  75. c.JSON(nil, err)
  76. c.AbortWithStatus(http.StatusServiceUnavailable)
  77. }
  78. }
  79. func initService(c *conf.Config) {
  80. spySrv = service.New(c)
  81. vfySvc = verify.New(nil)
  82. }