http.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/up-rating/conf"
  5. "go-common/app/job/main/up-rating/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. svr *service.Service
  11. )
  12. // Init init http router.
  13. func Init(c *conf.Config) {
  14. svr = service.New(conf.Conf)
  15. // bm
  16. engine := bm.DefaultServer(c.BM)
  17. initRouter(engine)
  18. if err := engine.Start(); err != nil {
  19. log.Error("engine.Start error(%v)", err)
  20. panic(err)
  21. }
  22. }
  23. func initRouter(e *bm.Engine) {
  24. e.Ping(ping)
  25. mr := e.Group("/x/internal/job/up-rating")
  26. mr.POST("/past/score", pastScore)
  27. mr.POST("/past/record", pastRecord)
  28. mr.POST("/score", score)
  29. mr.POST("/score/del", delScore)
  30. mr.POST("/statistics", statistics)
  31. mr.POST("/trend", trend)
  32. mr.POST("/trend/del", delTrends)
  33. mr.POST("/task/status", taskStatus)
  34. }
  35. // ping check server ok.
  36. func ping(c *bm.Context) {
  37. if err := svr.Ping(c); err != nil {
  38. log.Error("service ping error(%v)", err)
  39. c.AbortWithStatus(http.StatusServiceUnavailable)
  40. }
  41. }
  42. // Close http close
  43. func Close() {
  44. svr.Close()
  45. }