http.go 1.2 KB

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