http.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package http
  2. import (
  3. "go-common/app/admin/main/upload/conf"
  4. "go-common/app/admin/main/upload/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. authSvc *permit.Permit
  12. uaSvc *service.Service
  13. verifySvc *verify.Verify
  14. )
  15. // Init init
  16. func Init(c *conf.Config, s *service.Service) {
  17. initService(c, s)
  18. // init router
  19. engine := bm.DefaultServer(c.BM)
  20. innerRouter(engine)
  21. if err := engine.Start(); err != nil {
  22. log.Error("engine.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // initService init services.
  27. func initService(c *conf.Config, s *service.Service) {
  28. authSvc = permit.New(c.Auth)
  29. verifySvc = verify.New(nil)
  30. uaSvc = s
  31. }
  32. // innerRouter init outer router api path.
  33. func innerRouter(e *bm.Engine) {
  34. //init api
  35. e.Ping(ping)
  36. uploadAdmin := e.Group("/x/admin/upload")
  37. {
  38. uploadAdmin.POST("/add", add)
  39. uploadAdmin.GET("/list", authSvc.Permit(""), list)
  40. uploadAdmin.DELETE("/delete", authSvc.Permit(""), deleteFile)
  41. file := uploadAdmin.Group("/file")
  42. {
  43. file.POST("/upload", authSvc.Permit(""), InternalUploadAdminImage)
  44. file.DELETE("/delete", authSvc.Permit(""), deleteRawFile)
  45. }
  46. }
  47. uploadAdminV2 := e.Group("/x/admin/upload/v2")
  48. {
  49. uploadAdminV2.GET("/list", authSvc.Permit(""), multiList)
  50. uploadAdminV2.DELETE("/delete", authSvc.Permit(""), deleteFileV2)
  51. }
  52. bucket := uploadAdmin.Group("/bucket")
  53. {
  54. bucket.POST("/add", verifySvc.Verify, addBucket)
  55. bucket.GET("/list", listBucket)
  56. bucket.GET("/list/public", listPublicBucket)
  57. bucket.GET("/detail", detailBucket)
  58. dir := bucket.Group("/dir")
  59. {
  60. dir.POST("/add", verifySvc.Verify, addDir)
  61. }
  62. }
  63. }