http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/seq-server/conf"
  5. "go-common/app/service/main/seq-server/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. seqSvc *service.Service
  12. vrfSvc *verify.Verify
  13. )
  14. // Init init http router.
  15. func Init(c *conf.Config, s *service.Service) {
  16. seqSvc = s
  17. vrfSvc = verify.New(nil)
  18. en := bm.DefaultServer(c.BM)
  19. innerRouter(en)
  20. // init internal server
  21. if err := en.Start(); err != nil {
  22. log.Error("xhttp.Serve error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // innerRouter init inner router.
  27. func innerRouter(e *bm.Engine) {
  28. e.Ping(ping)
  29. e.Register(register)
  30. seq := e.Group("/x/internal/seq", vrfSvc.Verify)
  31. {
  32. seq.POST("/id", seqID)
  33. seq.POST("/id32", seqID32)
  34. seq.POST("/maxseq", maxSeq)
  35. }
  36. }
  37. // ping check server ok.
  38. func ping(c *bm.Context) {
  39. if err := seqSvc.Ping(c); err != nil {
  40. log.Error("seq-server ping error(%v)", err)
  41. c.AbortWithStatus(http.StatusServiceUnavailable)
  42. }
  43. }
  44. // register check server ok.
  45. func register(c *bm.Context) {
  46. c.JSON(nil, nil)
  47. }