http.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package http
  2. import (
  3. "go-common/app/interface/main/answer/conf"
  4. "go-common/app/interface/main/answer/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/antispam"
  8. "go-common/library/net/http/blademaster/middleware/auth"
  9. )
  10. var (
  11. authSvc *auth.Auth
  12. antSvc *antispam.Antispam
  13. svc *service.Service
  14. )
  15. // Init init
  16. func Init(c *conf.Config) {
  17. initService(c)
  18. engineOuter := bm.DefaultServer(c.BM)
  19. outerRouter(engineOuter)
  20. if err := engineOuter.Start(); err != nil {
  21. log.Error("engineOuter.Start() error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // initService init services.
  26. func initService(c *conf.Config) {
  27. authSvc = auth.New(c.AuthN)
  28. antSvc = antispam.New(c.Antispam)
  29. svc = service.New(c)
  30. }
  31. // outerRouter init outer router api path.
  32. func outerRouter(e *bm.Engine) {
  33. e.Ping(ping)
  34. og := e.Group("/x/answer", bm.CORS())
  35. {
  36. // 答题流程排序
  37. og.GET("/v3/base", authSvc.UserWeb, antSvc.Handler(), baseQus)
  38. og.POST("/v3/base/check", authSvc.User, checkBase)
  39. og.GET("/v3/extra", authSvc.User, antSvc.Handler(), extraQus)
  40. og.POST("/v3/extra/check", authSvc.UserWeb, checkExtra)
  41. og.GET("/v3/extra/score", authSvc.User, extraScore)
  42. og.GET("/user/birthday", authSvc.User, checkBirthDay)
  43. og.GET("/v3/pro/type", authSvc.User, proType)
  44. og.GET("/v3/pro", authSvc.UserWeb, antSvc.Handler(), proQus)
  45. og.POST("/v3/pro/check", authSvc.User, checkPro)
  46. og.GET("/v3/captcha/gt", authSvc.User, antSvc.Handler(), captcha)
  47. og.POST("/v3/captcha/check", authSvc.User, validate)
  48. og.GET("/v3/result", authSvc.GuestWeb, cool)
  49. og.POST("/rec/pendant", authSvc.User, pendantRec)
  50. }
  51. }
  52. func ping(c *bm.Context) {
  53. }