http.go 697 B

123456789101112131415161718192021222324252627282930313233343536
  1. package http
  2. import (
  3. "go-common/app/job/main/passport-game-local/conf"
  4. "go-common/app/job/main/passport-game-local/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. var (
  9. srv *service.Service
  10. )
  11. // Init init http sever instance.
  12. func Init(c *conf.Config, s *service.Service) {
  13. srv = s
  14. // init inner router
  15. eng := bm.DefaultServer(c.BM)
  16. initRouter(eng)
  17. // init inner server
  18. if err := eng.Start(); err != nil {
  19. log.Error("bm.DefaultServer error(%v)", err)
  20. panic(err)
  21. }
  22. }
  23. // initRouter init inner router.
  24. func initRouter(e *bm.Engine) {
  25. // health check
  26. e.Ping(ping)
  27. }
  28. // ping check server ok.
  29. func ping(c *bm.Context) {
  30. c.JSON(nil, srv.Ping(c))
  31. }