http.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package http
  2. import (
  3. "go-common/app/service/live/xcaptcha/service/v1"
  4. "net/http"
  5. "go-common/app/service/live/xcaptcha/conf"
  6. "go-common/app/service/live/xcaptcha/service"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. srv *service.Service
  13. vfy *verify.Verify
  14. xCaptchaService *v1.XCaptchaService
  15. )
  16. // Init init
  17. func Init(c *conf.Config) {
  18. srv = service.New(c)
  19. vfy = verify.New(c.Verify)
  20. engine := bm.DefaultServer(c.BM)
  21. xCaptchaService = v1.NewXCaptchaService(c)
  22. route(engine)
  23. if err := engine.Start(); err != nil {
  24. log.Error("bm Start error(%v)", err)
  25. panic(err)
  26. }
  27. }
  28. func route(e *bm.Engine) {
  29. e.Ping(ping)
  30. e.Register(register)
  31. g := e.Group("/x/xcaptcha")
  32. {
  33. g.GET("/start", vfy.Verify, howToStart)
  34. }
  35. e.GET("/xlive/internal/xcaptcha/v1/xcaptcha/verify", captchaVerify)
  36. }
  37. func ping(c *bm.Context) {
  38. if err := srv.Ping(c); err != nil {
  39. log.Error("ping error(%v)", err)
  40. c.AbortWithStatus(http.StatusServiceUnavailable)
  41. }
  42. }
  43. func register(c *bm.Context) {
  44. c.JSON(map[string]interface{}{}, nil)
  45. }
  46. // example for http request handler
  47. func howToStart(c *bm.Context) {
  48. c.String(0, "Golang 大法好 !!!")
  49. }