http.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package http
  2. import (
  3. "go-common/app/admin/main/appstatic/conf"
  4. "go-common/app/admin/main/appstatic/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. vfySvc *verify.Verify
  12. authSvc *permit.Permit
  13. apsSvc *service.Service
  14. )
  15. // Init http server
  16. func Init(c *conf.Config, s *service.Service) {
  17. initService(c, s)
  18. engine := bm.DefaultServer(c.BM)
  19. innerRouter(engine)
  20. // init internal server
  21. if err := engine.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // initService init service
  27. func initService(c *conf.Config, s *service.Service) {
  28. apsSvc = s
  29. authSvc = permit.New(c.Auth)
  30. vfySvc = verify.New(nil)
  31. }
  32. // innerRouter
  33. func innerRouter(e *bm.Engine) {
  34. // ping monitor
  35. e.GET("/monitor/ping", ping)
  36. // internal api
  37. bg := e.Group("/x/admin/appstatic/res")
  38. {
  39. bg.POST("/add_ver", authSvc.Permit("APP_RESOURCE_POOL_MGT"), addVer) // 从mgr上传,正式权限
  40. bg.POST("/add_ver_test", authSvc.Permit("APP_RESOURCE_POOL_MGT_EDIT"), addVer) // 从mgr上传,测试权限
  41. bg.POST("/upload", vfySvc.Verify, addVer) // 从其他系统上传
  42. bg.POST("/publish", vfySvc.Verify, publish) // 告知某资源包的第一次发布,用于触发增量包补充计算
  43. }
  44. }
  45. // ping check server ok.
  46. func ping(c *bm.Context) {}