http.go 1.0 KB

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