http.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/web-goblin/conf"
  5. "go-common/app/interface/main/web-goblin/service/share"
  6. "go-common/app/interface/main/web-goblin/service/web"
  7. "go-common/app/interface/main/web-goblin/service/wechat"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/http/blademaster/middleware/auth"
  11. )
  12. var (
  13. srvWeb *web.Service
  14. srvShare *share.Service
  15. srvWechat *wechat.Service
  16. authSvr *auth.Auth
  17. )
  18. // Init init .
  19. func Init(c *conf.Config) {
  20. authSvr = auth.New(c.Auth)
  21. srvWeb = web.New(c)
  22. srvShare = share.New(c)
  23. srvWechat = wechat.New(c)
  24. engine := bm.DefaultServer(c.BM)
  25. router(engine)
  26. if err := engine.Start(); err != nil {
  27. log.Error("engine.Start error(%v)", err)
  28. panic(err)
  29. }
  30. }
  31. func router(e *bm.Engine) {
  32. e.Ping(ping)
  33. e.Register(register)
  34. group := e.Group("/x/web-goblin")
  35. {
  36. miGroup := group.Group("/mi")
  37. {
  38. miGroup.GET("/full", fullshort)
  39. }
  40. channelGroup := group.Group("/channel")
  41. {
  42. channelGroup.GET("", authSvr.Guest, channel)
  43. }
  44. ugcGroup := group.Group("ugc")
  45. {
  46. ugcGroup.GET("/full", ugcfull)
  47. ugcGroup.GET("/increment", ugcincre)
  48. }
  49. pgcGroup := group.Group("pgc")
  50. {
  51. pgcGroup.GET("/full", pgcfull)
  52. pgcGroup.GET("/increment", pgcincre)
  53. }
  54. group.GET("/share/encourage", authSvr.User, encourage)
  55. group.GET("/recruit", recruit)
  56. weChatGroup := group.Group("/wechat")
  57. {
  58. weChatGroup.GET("/qrcode", qrcode)
  59. }
  60. }
  61. }
  62. func ping(c *bm.Context) {
  63. if err := srvWeb.Ping(c); err != nil {
  64. log.Error("web-goblin ping error(%v)", err)
  65. c.AbortWithStatus(http.StatusServiceUnavailable)
  66. }
  67. }
  68. func register(c *bm.Context) {
  69. c.JSON(map[string]interface{}{}, nil)
  70. }