You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bucket.go 3.1 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package api
  2. import (
  3. "net/http"
  4. "gitlink.org.cn/cloudream/common/sdks"
  5. clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
  6. )
  7. type BucketService struct {
  8. *Client
  9. }
  10. func (c *Client) Bucket() *BucketService {
  11. return &BucketService{c}
  12. }
  13. const BucketGetPath = "/bucket/get"
  14. type BucketGet struct {
  15. BucketID clitypes.BucketID `json:"bucketID" binding:"required"`
  16. }
  17. func (r *BucketGet) MakeParam() *sdks.RequestParam {
  18. return sdks.MakeJSONParam(http.MethodGet, BucketGetPath, r)
  19. }
  20. type BucketGetResp struct {
  21. Bucket clitypes.Bucket `json:"bucket"`
  22. }
  23. func (r *BucketGetResp) ParseResponse(resp *http.Response) error {
  24. return sdks.ParseCodeDataJSONResponse(resp, r)
  25. }
  26. func (c *BucketService) Get(req BucketGet) (*BucketGetResp, error) {
  27. return JSONAPI(&c.cfg, c.httpCli, &req, &BucketGetResp{})
  28. }
  29. const BucketGetByNamePath = "/bucket/getByName"
  30. type BucketGetByName struct {
  31. Name string `url:"name" form:"name" binding:"required"`
  32. }
  33. func (r *BucketGetByName) MakeParam() *sdks.RequestParam {
  34. return sdks.MakeQueryParam(http.MethodGet, BucketGetByNamePath, r)
  35. }
  36. type BucketGetByNameResp struct {
  37. Bucket clitypes.Bucket `json:"bucket"`
  38. }
  39. func (r *BucketGetByNameResp) ParseResponse(resp *http.Response) error {
  40. return sdks.ParseCodeDataJSONResponse(resp, r)
  41. }
  42. func (c *BucketService) GetByName(req BucketGetByName) (*BucketGetByNameResp, error) {
  43. return JSONAPI(&c.cfg, c.httpCli, &req, &BucketGetByNameResp{})
  44. }
  45. const BucketCreatePath = "/bucket/create"
  46. type BucketCreate struct {
  47. Name string `json:"name" binding:"required"`
  48. }
  49. func (r *BucketCreate) MakeParam() *sdks.RequestParam {
  50. return sdks.MakeJSONParam(http.MethodPost, BucketCreatePath, r)
  51. }
  52. type BucketCreateResp struct {
  53. Bucket clitypes.Bucket `json:"bucket"`
  54. }
  55. func (r *BucketCreateResp) ParseResponse(resp *http.Response) error {
  56. return sdks.ParseCodeDataJSONResponse(resp, r)
  57. }
  58. func (c *BucketService) Create(req BucketCreate) (*BucketCreateResp, error) {
  59. return JSONAPI(&c.cfg, c.httpCli, &req, &BucketCreateResp{})
  60. }
  61. const BucketDeletePath = "/bucket/delete"
  62. type BucketDelete struct {
  63. BucketID clitypes.BucketID `json:"bucketID" binding:"required"`
  64. }
  65. func (r *BucketDelete) MakeParam() *sdks.RequestParam {
  66. return sdks.MakeJSONParam(http.MethodPost, BucketDeletePath, r)
  67. }
  68. type BucketDeleteResp struct{}
  69. func (r *BucketDeleteResp) ParseResponse(resp *http.Response) error {
  70. return sdks.ParseCodeDataJSONResponse(resp, r)
  71. }
  72. func (c *BucketService) Delete(req BucketDelete) error {
  73. return JSONAPINoData(&c.cfg, c.httpCli, &req)
  74. }
  75. const BucketListAllPath = "/bucket/listAll"
  76. type BucketListAll struct {
  77. }
  78. func (r *BucketListAll) MakeParam() *sdks.RequestParam {
  79. return sdks.MakeQueryParam(http.MethodGet, BucketListAllPath, r)
  80. }
  81. type BucketListAllResp struct {
  82. Buckets []clitypes.Bucket `json:"buckets"`
  83. }
  84. func (r *BucketListAllResp) ParseResponse(resp *http.Response) error {
  85. return sdks.ParseCodeDataJSONResponse(resp, r)
  86. }
  87. func (c *BucketService) ListAll(req BucketListAll) (*BucketListAllResp, error) {
  88. return JSONAPI(&c.cfg, c.httpCli, &req, &BucketListAllResp{})
  89. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。