http.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/up-rating/conf"
  5. "go-common/app/admin/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
  13. func Init(c *conf.Config, s *service.Service) {
  14. svr = s
  15. engine := bm.DefaultServer(c.BM)
  16. initRouter(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("engine.Start error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. func initRouter(r *bm.Engine) {
  23. r.Ping(ping)
  24. rating := r.Group("/allowance/api/x/admin/rating")
  25. statis := rating.Group("/statis")
  26. {
  27. statis.GET("/graph", statisGraph)
  28. statis.GET("/list", statisList)
  29. statis.GET("/export", statisExport)
  30. }
  31. score := rating.Group("/score")
  32. {
  33. score.GET("/list", scoreList)
  34. score.GET("/export", scoreExport)
  35. score.GET("/up/current", scoreCurrent)
  36. score.GET("/up/history", scoreHistory)
  37. }
  38. param := rating.Group("/param")
  39. {
  40. param.POST("/insert", paramInsert)
  41. }
  42. trend := rating.Group("trend")
  43. {
  44. trend.GET("/ascend/list", ascList)
  45. trend.GET("/descend/list", descList)
  46. }
  47. au := rating.Group("authority")
  48. {
  49. au.POST("/add", addAuthority)
  50. au.POST("/remove", removeAuthority)
  51. }
  52. }
  53. // ping check server ok.
  54. func ping(c *bm.Context) {
  55. var err error
  56. if err = svr.Ping(c); err != nil {
  57. log.Error("up-rating-admin ping error(%v)", err)
  58. c.AbortWithStatus(http.StatusServiceUnavailable)
  59. }
  60. }