http.go 952 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/card/conf"
  5. "go-common/app/service/main/card/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. srv *service.Service
  12. verifySvc *verify.Verify
  13. )
  14. // Init init
  15. func Init(c *conf.Config, svc *service.Service) {
  16. srv = svc
  17. verifySvc = verify.New(nil)
  18. engine := bm.DefaultServer(c.BM)
  19. route(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("bm Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func route(e *bm.Engine) {
  26. e.Ping(ping)
  27. e.Register(register)
  28. group := e.Group("/x/internal/card", verifySvc.Verify)
  29. {
  30. group.GET("/bymids", byMids)
  31. }
  32. }
  33. func ping(c *bm.Context) {
  34. if err := srv.Ping(c); err != nil {
  35. log.Error("ping error(%v)", err)
  36. c.AbortWithStatus(http.StatusServiceUnavailable)
  37. }
  38. }
  39. func register(c *bm.Context) {
  40. c.JSON(map[string]interface{}{}, nil)
  41. }