http.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/openplatform/abtest/conf"
  5. "go-common/app/service/openplatform/abtest/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. abSvr *service.Service
  11. )
  12. // Init init account service.
  13. func Init(c *conf.Config, s *service.Service) {
  14. abSvr = s
  15. engineInner := bm.DefaultServer(c.BM.Inner)
  16. innerRouter(engineInner)
  17. // init Inner serve
  18. if err := engineInner.Start(); err != nil {
  19. log.Error("bm.DefaultServer error(%v)", err)
  20. panic(err)
  21. }
  22. engineOuter := bm.DefaultServer(c.BM.Outer)
  23. outerRouter(engineOuter)
  24. // init Outer serve
  25. if err := engineOuter.Start(); err != nil {
  26. log.Error("bm.DefaultServer error(%v)", err)
  27. panic(err)
  28. }
  29. }
  30. // innerRouter init inner router api path.
  31. func innerRouter(e *bm.Engine) {
  32. e.Ping(ping)
  33. group := e.Group("/openplatform/internal/abtest")
  34. {
  35. //common
  36. group.GET("/versionid", versionID)
  37. group.GET("/version", version)
  38. }
  39. group = e.Group("/openplatform/admin/abtest")
  40. {
  41. //mng abtest
  42. group.GET("/list", listAb)
  43. group.GET("/add", addAb)
  44. group.GET("/update", updateAb)
  45. group.GET("/status", updateStatus)
  46. group.GET("/delete", deleteAb)
  47. }
  48. group = e.Group("/openplatform/admin/abtest/group")
  49. {
  50. //mng group
  51. group.GET("/add", addGroup)
  52. group.GET("/list", listGroup)
  53. group.GET("/update", updateGroup)
  54. group.GET("/delete", deleteGroup)
  55. }
  56. group = e.Group("/openplatform/admin/abtest/stat")
  57. {
  58. group.GET("/total", total)
  59. }
  60. }
  61. // outerRouter init outer router.
  62. func outerRouter(e *bm.Engine) {
  63. }
  64. // ping check server ok.
  65. func ping(c *bm.Context) {
  66. if err := abSvr.Ping(c); err != nil {
  67. log.Error("open-abtest http service ping error(%v)", err)
  68. c.AbortWithStatus(http.StatusServiceUnavailable)
  69. }
  70. }