http.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package http
  2. import (
  3. "go-common/app/interface/openplatform/monitor-end/conf"
  4. "go-common/app/interface/openplatform/monitor-end/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/auth"
  8. "net/http"
  9. )
  10. var (
  11. mfSvc *service.Service
  12. authSvr *auth.Auth
  13. )
  14. // Init init account service.
  15. func Init(c *conf.Config, s *service.Service) {
  16. authSvr = auth.New(nil)
  17. mfSvc = s
  18. // engine
  19. engine := bm.DefaultServer(c.BM)
  20. innerRouter(engine)
  21. // init inner server
  22. if err := engine.Start(); err != nil {
  23. log.Error("engine.Start() error(%v)", err)
  24. panic(err)
  25. }
  26. }
  27. // innerRouter init inner router.
  28. func innerRouter(e *bm.Engine) {
  29. e.Ping(ping)
  30. e.Register(register)
  31. group := e.Group("/open/monitor", authSvr.Guest)
  32. {
  33. group.GET("/report", report)
  34. group.GET("/err/collect", collect)
  35. }
  36. group = e.Group("open/internal/monitor", authSvr.Guest)
  37. {
  38. group.GET("/report", report)
  39. group.GET("/consume/start", startConsume)
  40. group.GET("/consume/stop", stopConsume)
  41. group.GET("/consume/pause", pauseConsume)
  42. r := group.Group("/alert")
  43. {
  44. cr := r.Group("/group")
  45. {
  46. cr.GET("/list", groupList)
  47. cr.POST("/update", groupUpdate)
  48. cr.POST("/add", groupAdd)
  49. cr.POST("/delete", groupDelete)
  50. }
  51. cr = r.Group("/target")
  52. {
  53. cr.GET("/list", targetList)
  54. cr.POST("/update", targetUpdate)
  55. cr.POST("/add", targetAdd)
  56. cr.POST("/sync", targetSync)
  57. }
  58. cr = r.Group("/product")
  59. {
  60. cr.POST("/add", productAdd)
  61. cr.POST("/update", productUpdate)
  62. cr.POST("/delete", productDelete)
  63. cr.GET("/list", productList)
  64. }
  65. }
  66. }
  67. }
  68. // ping check server ok.
  69. func ping(c *bm.Context) {
  70. if err := mfSvc.Ping(c); err != nil {
  71. log.Error("ping error(%v)", err)
  72. c.AbortWithStatus(http.StatusServiceUnavailable)
  73. }
  74. }
  75. // register support discovery.
  76. func register(c *bm.Context) {
  77. c.JSON(map[string]struct{}{}, nil)
  78. }