http.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package http
  2. import (
  3. "go-common/app/service/live/dao-anchor/conf"
  4. "go-common/app/service/live/dao-anchor/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/verify"
  8. )
  9. var (
  10. srv *service.Service
  11. vfy *verify.Verify
  12. )
  13. // Init init
  14. func Init(c *conf.Config) {
  15. vfy = verify.New(c.Verify)
  16. initService(c)
  17. engine := bm.DefaultServer(c.BM)
  18. route(engine)
  19. if err := engine.Start(); err != nil {
  20. log.Error("bm Start error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. func initService(c *conf.Config) {
  25. srv = service.New(c)
  26. }
  27. func route(e *bm.Engine) {
  28. e.Ping(ping)
  29. e.Register(register)
  30. g := e.Group("/xlive/dao-anchor")
  31. {
  32. g.GET("/start", vfy.Verify, howToStart)
  33. }
  34. }
  35. func ping(c *bm.Context) {
  36. // TODO
  37. /*if err := srv.Ping(c); err != nil {
  38. log.Error("ping error(%v)", err)
  39. c.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. }