http.go 912 B

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