http.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package http
  2. import (
  3. v12 "go-common/app/interface/live/web-room/api/http/v1"
  4. "go-common/app/interface/live/web-room/conf"
  5. "go-common/app/interface/live/web-room/service"
  6. "go-common/app/interface/live/web-room/service/v1"
  7. v1index "go-common/app/interface/live/web-room/service/v1/dm"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/http/blademaster/middleware/auth"
  11. "net/http"
  12. )
  13. var (
  14. authn *auth.Auth
  15. srv *service.Service
  16. dmservice *v1index.DMService
  17. )
  18. // Init init
  19. func Init(c *conf.Config) {
  20. srv = service.New(c)
  21. initService(c)
  22. engine := bm.DefaultServer(c.BM)
  23. route(engine)
  24. if err := engine.Start(); err != nil {
  25. log.Error("bm Start error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. func initService(c *conf.Config) {
  30. dmservice = v1index.NewDMService(c)
  31. authn = auth.New(c.AuthN)
  32. }
  33. func route(e *bm.Engine) {
  34. e.Ping(ping)
  35. e.Register(register)
  36. g := e.Group("/xlive/web-room")
  37. g.POST("/v1/dM/sendmsg", authn.User, sendMsgSendMsg)
  38. g.POST("/v1/dM/gethistory", getHistory)
  39. v12.RegisterV1CaptchaService(e, v1.NewCaptchaService(conf.Conf), map[string]bm.HandlerFunc{
  40. "auth": authn.User,
  41. })
  42. v12.RegisterV1RoomAdminService(e, v1.NewRoomAdminService(conf.Conf), map[string]bm.HandlerFunc{})
  43. }
  44. func ping(c *bm.Context) {
  45. if err := srv.Ping(c); err != nil {
  46. log.Error("ping error(%v)", err)
  47. c.AbortWithStatus(http.StatusServiceUnavailable)
  48. }
  49. }
  50. func register(c *bm.Context) {
  51. c.JSON(map[string]interface{}{}, nil)
  52. }