http.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/open/conf"
  5. "go-common/app/admin/main/open/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. mngSvc *service.Service
  12. idfSvc *verify.Verify
  13. )
  14. // Init init http sever instance.
  15. func Init(c *conf.Config, s *service.Service) {
  16. mngSvc = s
  17. idfSvc = verify.New(c.Verify)
  18. // init inner router
  19. engineIn := bm.DefaultServer(nil)
  20. innerRouter(engineIn)
  21. // init inner server
  22. if err := engineIn.Start(); err != nil {
  23. log.Error("enginIn.Start.error", err)
  24. panic(err)
  25. }
  26. }
  27. // innerRouter.
  28. func innerRouter(e *bm.Engine) {
  29. e.Ping(ping)
  30. g := e.Group("/x/admin/open")
  31. {
  32. gapp := g.Group("/app", idfSvc.Verify)
  33. {
  34. gapp.POST("/add", addApp)
  35. gapp.POST("/delete", delApp)
  36. gapp.POST("/update", updateApp)
  37. gapp.GET("/list", listApp)
  38. }
  39. }
  40. }
  41. // ping check server ok.
  42. func ping(c *bm.Context) {
  43. if err := mngSvc.Ping(c); err != nil {
  44. log.Error("service ping error(%v)", err)
  45. c.AbortWithStatus(http.StatusServiceUnavailable)
  46. }
  47. }