http.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/kvo/conf"
  5. "go-common/app/interface/main/kvo/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/auth"
  9. )
  10. var (
  11. kvoSvr *service.Service
  12. authSvr *auth.Auth
  13. )
  14. // Init init http
  15. func Init(c *conf.Config) {
  16. kvoSvr = service.New(c)
  17. authSvr = auth.New(c.Auth)
  18. // init outer router
  19. engineOut := bm.DefaultServer(c.BM)
  20. outerRouter(engineOut)
  21. if err := engineOut.Start(); err != nil {
  22. log.Error("engineOut.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. func outerRouter(e *bm.Engine) {
  27. e.Ping(ping)
  28. group := e.Group("/x/kvo", bm.CORS())
  29. {
  30. group.GET("/web/doc/get", authSvr.UserWeb, doc)
  31. group.POST("/web/doc/add", authSvr.UserWeb, addDoc)
  32. group.GET("/app/doc/get", authSvr.UserMobile, doc)
  33. group.POST("/app/doc/add", authSvr.UserMobile, addDoc)
  34. }
  35. }
  36. // ping check server ok.
  37. func ping(c *bm.Context) {
  38. var err error
  39. if err = kvoSvr.Ping(c); err != nil {
  40. log.Error("kvo service ping error(%v)", err)
  41. c.AbortWithStatus(http.StatusServiceUnavailable)
  42. }
  43. }