http.go 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/up/conf"
  5. "go-common/app/job/main/up/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. svc *service.Service
  11. )
  12. // Init init
  13. func Init(c *conf.Config) {
  14. svc = service.New(c)
  15. engine := bm.DefaultServer(c.BM)
  16. route(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("bm Start error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. func route(e *bm.Engine) {
  23. e.Ping(ping)
  24. e.Register(register)
  25. g := e.Group("/x/job/up")
  26. {
  27. g.GET("/job/run", runJob)
  28. g.GET("/start")
  29. g.GET("/job/warm-up", warmUp)
  30. g.GET("/job/warm-up-mid", warmUpMid)
  31. g.GET("/job/add-staff", addStaff)
  32. g.GET("/job/delete-staff", deleteStaff)
  33. }
  34. }
  35. func ping(c *bm.Context) {
  36. if err := svc.Ping(c); err != nil {
  37. log.Error("ping error(%v)", err)
  38. c.AbortWithStatus(http.StatusServiceUnavailable)
  39. }
  40. }
  41. func register(c *bm.Context) {
  42. c.JSON(map[string]interface{}{}, nil)
  43. }