http.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "go-common/app/infra/databus/conf"
  4. "go-common/app/infra/databus/service"
  5. "go-common/app/infra/databus/tcp"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. svc *service.Service
  11. )
  12. // Init init https
  13. func Init(c *conf.Config, s *service.Service) {
  14. svc = s
  15. // router
  16. router := bm.DefaultServer(c.HTTPServer)
  17. initRouter(router)
  18. // init internal server
  19. if err := router.Start(); err != nil {
  20. log.Error("bm.DefaultServer error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. // initRouter init local router api path.
  25. func initRouter(e *bm.Engine) {
  26. e.Ping(ping)
  27. e.Register(register)
  28. e.GET("/databus/consumer/addrs", consumerAddrs)
  29. e.POST("/databus/pub", pub)
  30. }
  31. // ping check server ok
  32. func ping(c *bm.Context) {
  33. }
  34. // register provid for discovery.
  35. func register(c *bm.Context) {
  36. c.JSON(map[string]struct{}{
  37. "data": struct{}{},
  38. }, nil)
  39. }
  40. // consumerAddrs get consumer addrs.
  41. func consumerAddrs(c *bm.Context) {
  42. group := c.Request.Form.Get("group")
  43. c.JSON(tcp.ConsumerAddrs(group))
  44. }