http.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/laser/conf"
  5. "go-common/app/admin/main/laser/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. svc *service.Service
  12. authSrc *permit.Permit
  13. )
  14. // Init http server
  15. func Init(c *conf.Config) {
  16. svc = service.New(c)
  17. authSrc = permit.New(c.Auth)
  18. engine := bm.DefaultServer(c.BM)
  19. initRouter(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func initRouter(e *bm.Engine) {
  26. e.Ping(ping)
  27. laser := e.Group("/x/admin/laser", authSrc.Verify())
  28. {
  29. task := laser.Group("/task")
  30. {
  31. task.POST("/add", addTask)
  32. task.GET("/list", queryTask)
  33. task.POST("/edit", updateTask)
  34. task.POST("/delete", deleteTask)
  35. }
  36. taskLog := laser.Group("/task_log")
  37. {
  38. taskLog.GET("/list", queryTaskLog)
  39. }
  40. recheck := laser.Group("/archive/stat")
  41. {
  42. recheck.GET("/panel", recheckPanel)
  43. recheck.GET("/user", recheckUser)
  44. recheck.GET("/123_recheck", recheck123)
  45. }
  46. cargo := laser.Group("/archive/cargo")
  47. {
  48. cargo.GET("/audit/csv", auditCargoCsv)
  49. cargo.GET("/auditors", auditorCargo)
  50. }
  51. tag := laser.Group("/archive/tag")
  52. {
  53. tag.GET("/recheck", tagRecheck)
  54. }
  55. video := laser.Group("/video/stat")
  56. {
  57. video.GET("/random_video", randomVideo)
  58. video.GET("/random_video/csv", csvRandomVideo)
  59. video.GET("/fixed_video", fixedVideo)
  60. video.GET("/fixed_video/csv", csvFixedVideo)
  61. }
  62. }
  63. }
  64. // ping check server ok.
  65. func ping(c *bm.Context) {
  66. if err := svc.Ping(c); err != nil {
  67. log.Error("laser-admin service ping error")
  68. c.AbortWithStatus(http.StatusServiceUnavailable)
  69. }
  70. }