http.go 880 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/account-summary/conf"
  5. "go-common/app/job/main/account-summary/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. router(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("bm.DefaultServer error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. func router(e *bm.Engine) {
  23. e.Ping(ping)
  24. e.Register(register)
  25. g := e.Group("/x/internal/account-summary")
  26. {
  27. g.GET("/sync/one", syncOne)
  28. g.GET("/get/one", getOne)
  29. }
  30. }
  31. func ping(c *bm.Context) {
  32. if err := srv.Ping(c); err != nil {
  33. log.Error("account-summary-job ping error(%v)", err)
  34. c.AbortWithStatus(http.StatusServiceUnavailable)
  35. }
  36. }
  37. func register(c *bm.Context) {
  38. c.JSON(map[string]interface{}{}, nil)
  39. }