http.go 860 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/web-goblin/conf"
  5. "go-common/app/job/main/web-goblin/service/esports"
  6. "go-common/app/job/main/web-goblin/service/web"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. var (
  11. srvweb *web.Service
  12. srvesp *esports.Service
  13. )
  14. // Init init
  15. func Init(c *conf.Config) {
  16. srvweb = web.New(c)
  17. srvesp = esports.New(c)
  18. engine := bm.DefaultServer(c.BM)
  19. router(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func router(e *bm.Engine) {
  26. e.Ping(ping)
  27. e.Register(register)
  28. }
  29. func ping(c *bm.Context) {
  30. if err := srvweb.Ping(c); err != nil {
  31. log.Error("web-goblin-job ping error(%v)", err)
  32. c.AbortWithStatus(http.StatusServiceUnavailable)
  33. }
  34. }
  35. func register(c *bm.Context) {
  36. c.JSON(map[string]interface{}{}, nil)
  37. }