http.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package http
  2. import (
  3. "go-common/app/admin/main/point/conf"
  4. "go-common/app/admin/main/point/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. svc *service.Service
  11. authSvc *permit.Permit
  12. )
  13. // Init init
  14. func Init(c *conf.Config) {
  15. initService(c)
  16. // init router
  17. engine := bm.DefaultServer(c.BM)
  18. initRouter(engine)
  19. if err := engine.Start(); err != nil {
  20. log.Error("engine.Start error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. // initService init services.
  25. func initService(c *conf.Config) {
  26. authSvc = permit.New(c.Auth)
  27. svc = service.New(c)
  28. }
  29. // initRouter init outer router api path.
  30. func initRouter(e *bm.Engine) {
  31. //init api
  32. e.Ping(ping)
  33. group := e.Group("/x/admin/point", authSvc.Permit("VIP_POINT"))
  34. {
  35. group.GET("/conf/list", pointConfList)
  36. group.GET("/conf/info", pointConfInfo)
  37. group.POST("/conf/add", pointConfAdd)
  38. group.POST("/conf/edit", pointConfEdit)
  39. group.GET("/history/list", pointHistory)
  40. group.POST("/user/add", pointUserAdd)
  41. }
  42. }
  43. // ping check server ok.
  44. func ping(c *bm.Context) {
  45. svc.Ping(c)
  46. }