bucekt.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/upload/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. "go-common/library/net/http/blademaster/render"
  9. )
  10. func addBucket(c *bm.Context) {
  11. var err error
  12. abp := new(model.AddBucketParam)
  13. if err = c.BindWith(abp, binding.FormPost); err != nil {
  14. return
  15. }
  16. if len(abp.KeyID) != 16 {
  17. c.Render(http.StatusOK, render.JSON{
  18. Code: ecode.RequestErr.Code(),
  19. Message: "key_id should length 16",
  20. Data: nil,
  21. })
  22. c.Abort()
  23. return
  24. }
  25. if len(abp.KeySecret) != 30 {
  26. c.Render(http.StatusOK, render.JSON{
  27. Code: ecode.RequestErr.Code(),
  28. Message: "key_secret should length 30",
  29. Data: nil,
  30. })
  31. c.Abort()
  32. return
  33. }
  34. c.JSON(nil, uaSvc.AddBucket(c, abp))
  35. }
  36. func listBucket(c *bm.Context) {
  37. var err error
  38. lbp := new(model.ListBucketParam)
  39. if err = c.Bind(lbp); err != nil {
  40. return
  41. }
  42. c.JSON(uaSvc.ListBucket(c, lbp))
  43. }
  44. func listPublicBucket(c *bm.Context) {
  45. var err error
  46. lbp := new(model.ListBucketParam)
  47. if err = c.Bind(lbp); err != nil {
  48. return
  49. }
  50. c.JSON(uaSvc.ListPublicBucket(c, lbp))
  51. }
  52. func detailBucket(c *bm.Context) {
  53. var err error
  54. dbp := new(struct {
  55. Bucket string `json:"bucket" form:"bucket" validate:"required"`
  56. })
  57. if err = c.Bind(dbp); err != nil {
  58. return
  59. }
  60. c.JSON(uaSvc.DetailBucket(c, dbp.Bucket))
  61. }