http.go 804 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/mcn/conf"
  5. "go-common/app/job/main/mcn/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. srv *service.Service
  11. )
  12. // Init init
  13. func Init(c *conf.Config) {
  14. srv = 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/mcn") // authSvc.Verify() manager use
  26. {
  27. g.GET("/run", run)
  28. }
  29. }
  30. func ping(c *bm.Context) {
  31. if err := srv.Ping(c); err != nil {
  32. log.Error("ping error(%v)", err)
  33. c.AbortWithStatus(http.StatusServiceUnavailable)
  34. }
  35. }
  36. func register(c *bm.Context) {
  37. c.JSON(map[string]interface{}{}, nil)
  38. }