http.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/passport/conf"
  5. "go-common/app/service/main/passport/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. passportSvc *service.Service
  12. vfy *verify.Verify
  13. )
  14. // Init fot init open service
  15. func Init(c *conf.Config, s *service.Service) {
  16. passportSvc = s
  17. vfy = verify.New(c.Identify)
  18. // engine
  19. engIn := bm.DefaultServer(c.BM)
  20. innerRouter(c, engIn)
  21. // init inner server
  22. if err := engIn.Start(); err != nil {
  23. log.Error("bm.Start error(%v)", err)
  24. panic(err)
  25. }
  26. }
  27. func innerRouter(c *conf.Config, e *bm.Engine) {
  28. e.Ping(ping)
  29. e.Register(register)
  30. group := e.Group("/x/internal/passport", vfy.Verify)
  31. {
  32. group.GET("/records/face", face)
  33. if c.Switch.LoginLogHBase {
  34. group.GET("records/loginlog", loginLog)
  35. }
  36. group.POST("/history/pwd/check", historyPwdCheck)
  37. }
  38. }
  39. // ping check server ok.
  40. func ping(c *bm.Context) {
  41. if err := passportSvc.Ping(c); err != nil {
  42. log.Error("ping error(%v)", err)
  43. c.AbortWithStatus(http.StatusServiceUnavailable)
  44. }
  45. }
  46. // register support discovery.
  47. func register(c *bm.Context) {
  48. c.JSON(map[string]struct{}{}, nil)
  49. }