http.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package http
  2. import (
  3. "go-common/app/admin/main/answer/conf"
  4. "go-common/app/admin/main/answer/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. answerSvc *service.Service
  11. permitX *permit.Permit
  12. )
  13. // Init init http sever instance.
  14. func Init(c *conf.Config, s *service.Service) {
  15. answerSvc = s
  16. permitX = permit.New(c.Auth)
  17. // init inner router
  18. engine := bm.DefaultServer(c.BM)
  19. innerRouter(engine)
  20. // init inner server
  21. if err := engine.Start(); err != nil {
  22. log.Error("xhttp.Serve inner error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // innerRouter init inner router.
  27. func innerRouter(e *bm.Engine) {
  28. // health check
  29. e.Ping(ping)
  30. //internal api
  31. que := e.Group("/x/admin/answer/v3")
  32. {
  33. que.GET("/types", types)
  34. que.GET("/questions", permitX.Permit("ANSWER_LIST"), quesList)
  35. que.POST("/upload", permitX.Permit("ANSWER_UPLOAD"), uploadQsts)
  36. que.POST("/question/edit", permitX.Permit("ANSWER_EDIT"), queEdit)
  37. que.POST("/question/disable", permitX.Permit("ANSWER_DISABLE"), queDisable)
  38. que.GET("/question/history", queHistory)
  39. que.GET("/history", history)
  40. que.GET("/load/img", loadImg)
  41. }
  42. }
  43. // ping check server ok.
  44. func ping(c *bm.Context) {}