http.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/secure/conf"
  5. "go-common/app/service/main/secure/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. rSrv *service.Service
  12. verSvc *verify.Verify
  13. )
  14. // Init init http service
  15. func Init(s *service.Service) {
  16. initService(s)
  17. e := bm.DefaultServer(conf.Conf.BM)
  18. innerRouter(e)
  19. if err := e.Start(); err != nil {
  20. log.Error("e.Start() error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. func initService(s *service.Service) {
  25. rSrv = s
  26. verSvc = verify.New(conf.Conf.Verify)
  27. }
  28. // innerRouter init local router api path.
  29. func innerRouter(e *bm.Engine) {
  30. e.Ping(ping)
  31. e.Register(register)
  32. group := e.Group("/x/internal/secure", verSvc.Verify)
  33. {
  34. group.GET("/loc", getLoc)
  35. group.POST("/often/check", oftenCheck)
  36. expect := group.Group("/expect")
  37. {
  38. expect.GET("/status", status)
  39. expect.POST("/close", closeNotify)
  40. expect.GET("/loc", loc)
  41. expect.POST("/feedback", feedback)
  42. expect.POST("/test", addlog)
  43. }
  44. }
  45. }
  46. // ping check server ok.
  47. func ping(c *bm.Context) {
  48. if err := rSrv.Ping(c); err != nil {
  49. log.Error("ping error(%+v)", err)
  50. c.AbortWithStatus(http.StatusServiceUnavailable)
  51. }
  52. }
  53. // register check server ok.
  54. func register(c *bm.Context) {
  55. c.JSON(map[string]interface{}{}, nil)
  56. }