http.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/credit/conf"
  5. "go-common/app/admin/main/credit/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. )
  10. var (
  11. authSvc *permit.Permit
  12. creSvc *service.Service
  13. )
  14. // Init http server
  15. func Init(c *conf.Config) {
  16. initService(c)
  17. engine := bm.DefaultServer(c.BM)
  18. innerRouter(engine)
  19. // init internal server
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // initService init service
  26. func initService(c *conf.Config) {
  27. creSvc = service.New(c)
  28. authSvc = permit.New(c.Auth)
  29. }
  30. // innerRouter
  31. func innerRouter(e *bm.Engine) {
  32. // ping monitor
  33. e.Ping(ping)
  34. // internal api
  35. bg := e.Group("/x/admin/credit/blocked")
  36. {
  37. // info
  38. bg.GET("/info", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO"), infos) // 封禁列表
  39. bg.GET("/info/id", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO_ID"), infoByID) // 封禁信息详情
  40. bg.POST("/info/up", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO_UP"), upInfo) // 编辑封禁列表
  41. bg.POST("/info/del", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO_DEL"), delInfo) // 删除封禁列表
  42. bg.POST("/info/status/up", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO_STATUS_UP"), upInfoStatus) // 更新封禁列表状态
  43. bg.GET("/info.so", authSvc.Permit("BLACK_HOUSE_BLOCKED_INFO_SO"), infosEx) // 封禁列表导出
  44. // publish
  45. bg.GET("/publish", authSvc.Permit("BLACK_HOUSE_BLOCKED_PUBLISH"), publishs) // 公告列表
  46. bg.GET("/publish/id", authSvc.Permit("BLACK_HOUSE_BLOCKED_PUBLISH_ID"), publishByID) // 公告信息详情
  47. bg.POST("/publish/add", authSvc.Permit("BLACK_HOUSE_BLOCKED_PUBLISH_ADD"), addPublish) // 增加公告
  48. bg.POST("/publish/up", authSvc.Permit("BLACK_HOUSE_BLOCKED_PUBLISH_UP"), upPublish) // 更新公告
  49. bg.POST("/publish/del", authSvc.Permit("BLACK_HOUSE_BLOCKED_PUBLISH_DEL"), delPublish) // 删除公告
  50. // notice
  51. bg.GET("/notice", authSvc.Permit("BLACK_HOUSE_BLOCKED_NOTICE"), notices) // 通知列表
  52. bg.POST("/notice/add", authSvc.Permit("BLACK_HOUSE_BLOCKED_NOTICE_ADD"), addNotice) // 增加通知
  53. bg.POST("/notice/status/up", authSvc.Permit("BLACK_HOUSE_BLOCKED_NOTICE_STATUS_UP"), upNoticeStatus) // 更新通知
  54. }
  55. jg := e.Group("/x/admin/credit/jury")
  56. {
  57. // case
  58. jg.GET("/case", authSvc.Permit("BLACK_HOUSE_JURY_CASE"), cases) // 案件列表
  59. jg.GET("/case/id", authSvc.Permit("BLACK_HOUSE_JURY_CASE_ID"), caseByID) // 案件信息详情
  60. jg.GET("/case/reason", authSvc.Permit("BLACK_HOUSE_JURY_CASE_REASON"), reasons) // 案件举报理由
  61. jg.POST("/case/add", authSvc.Permit("BLACK_HOUSE_JURY_CASE_ADD"), addCase)
  62. jg.POST("/case/up", authSvc.Permit("BLACK_HOUSE_JURY_CASE_UP"), upCase)
  63. jg.POST("/case/vote/add", authSvc.Permit("BLACK_HOUSE_JURY_CASE_VOTE_ADD"), addCaseVote)
  64. jg.POST("/case/status/up", authSvc.Permit("BLACK_HOUSE_JURY_CASE_STATUS_UP"), upCaseStatus)
  65. jg.POST("/case/type/add", authSvc.Permit("BLACK_HOUSE_JURY_CASE_TYPE_ADD"), addCaseType) // 添加众裁稿件
  66. jg.GET("/case/auto/conf", authSvc.Permit("BLACK_HOUSE_JURY_CASE_AUTO_CONF"), autoCaseConfig)
  67. jg.POST("/case/auto/conf/set", authSvc.Permit("BLACK_HOUSE_JURY_CASE_AUTO_CONF_SET"), setAutoCaseConfig)
  68. // opinions
  69. jg.GET("/opinion", authSvc.Permit("BLACK_HOUSE_JURY_OPINION"), opinions) // 观点列表
  70. jg.GET("/opinion/id", authSvc.Permit("BLACK_HOUSE_JURY_OPINION_ID"), opinionByID) // 观点信息详情
  71. jg.POST("/opinion/del", authSvc.Permit("BLACK_HOUSE_JURY_OPINION_DEL"), delOpinions)
  72. // users
  73. jg.GET("/users", authSvc.Permit("BLACK_HOUSE_JURY_USERS"), users) // 委员列表
  74. jg.GET("/user/id", authSvc.Permit("BLACK_HOUSE_JURY_USER_ID"), userByID) // 委员信息详情
  75. jg.POST("/user/add", authSvc.Permit("BLACK_HOUSE_JURY_USER_ADD"), userAdd) // 新增委员
  76. jg.POST("/users/status/up", authSvc.Permit("BLACK_HOUSE_JURY_USERS_STATUS_UP"), upUserStatus)
  77. jg.POST("/users/blackwhite", authSvc.Permit("BLACK_HOUSE_JURY_USERS_BLACKWHITE"), blackWhite)
  78. jg.GET("/users.so", authSvc.Permit("BLACK_HOUSE_JURY_USERS_SO"), usersEx)
  79. // kpi
  80. jg.GET("/kpi", authSvc.Permit("BLACK_HOUSE_JURY_KPI"), kpis)
  81. jg.GET("/kpi/point", authSvc.Permit("BLACK_HOUSE_JURY_KPI_POINT"), kpiPoints)
  82. jg.GET("/kpi.so", authSvc.Permit("BLACK_HOUSE_JURY_KPI_SO"), kpisEx)
  83. // config
  84. jg.GET("/config", authSvc.Permit("BLACK_HOUSE_JURY_CONFIG"), caseConf)
  85. jg.POST("/config/set", authSvc.Permit("BLACK_HOUSE_JURY_CONFIG_SET"), setCaseConf)
  86. jg.GET("/votenum/conf", authSvc.Permit("BLACK_HOUSE_VOTENUM_CONFIG"), votenumConf)
  87. jg.POST("/votenum/conf/set", authSvc.Permit("BLACK_HOUSE_VOTENUM_CONFIG_SET"), setVotenumConf)
  88. }
  89. ug := e.Group("/x/admin/credit/upload")
  90. {
  91. ug.POST("", upload)
  92. ug.POST("/coins", annualCoins)
  93. }
  94. lg := e.Group("/x/admin/credit/labour")
  95. {
  96. /*
  97. lg.GET("/quest", question)
  98. lg.POST("/quest/statistics", statQuestion)
  99. */
  100. lg.POST("/quest/oper", operQuestion)
  101. lg.POST("/quest/del", delQuestion)
  102. }
  103. ig := e.Group("/x/admin/credit/jury")
  104. {
  105. // appeal webhook for internal .
  106. ig.POST("/webhook", webHook)
  107. }
  108. }
  109. // ping check server ok.
  110. func ping(c *bm.Context) {
  111. err := creSvc.Ping(c)
  112. if err != nil {
  113. log.Error("credit admin ping error")
  114. c.AbortWithStatus(http.StatusServiceUnavailable)
  115. }
  116. }