http.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package http
  2. import (
  3. "go-common/app/admin/openplatform/sug/conf"
  4. "go-common/app/admin/openplatform/sug/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. )
  9. var (
  10. srv *service.Service
  11. authSrv *permit.Permit
  12. )
  13. // Init init
  14. func Init(c *conf.Config, s *service.Service) {
  15. srv = s
  16. authSrv = permit.New(c.Auth)
  17. engine := bm.DefaultServer(c.BM)
  18. router(engine)
  19. if err := engine.Start(); err != nil {
  20. log.Error("engine.Start error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. // outerRouter init outer router api path.
  25. func router(e *bm.Engine) {
  26. //init api
  27. e.Ping(ping)
  28. group := e.Group("/x/admin/sug")
  29. {
  30. seasonGroup := group.Group("/season")
  31. {
  32. seasonGroup.GET("/source/search", sourceSearch)
  33. seasonGroup.GET("/match/search", search)
  34. seasonGroup.POST("/match/operate", matchOperate)
  35. }
  36. }
  37. }
  38. // ping check server ok.
  39. func ping(c *bm.Context) {
  40. if err := srv.Ping(c); err != nil {
  41. c.Error = err
  42. c.AbortWithStatus(503)
  43. }
  44. }