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 2.6 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 BucketGetByNamePath = "/bucket/getByName"
  14. type BucketGetByName struct {
  15. Name string `url:"name" form:"name" binding:"required"`
  16. }
  17. func (r *BucketGetByName) MakeParam() *sdks.RequestParam {
  18. return sdks.MakeQueryParam(http.MethodGet, BucketGetByNamePath, r)
  19. }
  20. type BucketGetByNameResp struct {
  21. Bucket clitypes.Bucket `json:"bucket"`
  22. }
  23. func (r *BucketGetByNameResp) ParseResponse(resp *http.Response) error {
  24. return sdks.ParseCodeDataJSONResponse(resp, r)
  25. }
  26. func (c *BucketService) GetByName(req BucketGetByName) (*BucketGetByNameResp, error) {
  27. return JSONAPI(c.cfg, http.DefaultClient, &req, &BucketGetByNameResp{})
  28. }
  29. const BucketCreatePath = "/bucket/create"
  30. type BucketCreate struct {
  31. Name string `json:"name" binding:"required"`
  32. }
  33. func (r *BucketCreate) MakeParam() *sdks.RequestParam {
  34. return sdks.MakeJSONParam(http.MethodPost, BucketCreatePath, r)
  35. }
  36. type BucketCreateResp struct {
  37. Bucket clitypes.Bucket `json:"bucket"`
  38. }
  39. func (r *BucketCreateResp) ParseResponse(resp *http.Response) error {
  40. return sdks.ParseCodeDataJSONResponse(resp, r)
  41. }
  42. func (c *BucketService) Create(req BucketCreate) (*BucketCreateResp, error) {
  43. return JSONAPI(c.cfg, http.DefaultClient, &req, &BucketCreateResp{})
  44. }
  45. const BucketDeletePath = "/bucket/delete"
  46. type BucketDelete struct {
  47. BucketID clitypes.BucketID `json:"bucketID" binding:"required"`
  48. }
  49. func (r *BucketDelete) MakeParam() *sdks.RequestParam {
  50. return sdks.MakeJSONParam(http.MethodPost, BucketDeletePath, r)
  51. }
  52. type BucketDeleteResp struct{}
  53. func (r *BucketDeleteResp) ParseResponse(resp *http.Response) error {
  54. return sdks.ParseCodeDataJSONResponse(resp, r)
  55. }
  56. func (c *BucketService) Delete(req BucketDelete) error {
  57. return JSONAPINoData(c.cfg, http.DefaultClient, &req)
  58. }
  59. const BucketListAllPath = "/bucket/listAll"
  60. type BucketListAll struct {
  61. }
  62. func (r *BucketListAll) MakeParam() *sdks.RequestParam {
  63. return sdks.MakeQueryParam(http.MethodGet, BucketListAllPath, r)
  64. }
  65. type BucketListAllResp struct {
  66. Buckets []clitypes.Bucket `json:"buckets"`
  67. }
  68. func (r *BucketListAllResp) ParseResponse(resp *http.Response) error {
  69. return sdks.ParseCodeDataJSONResponse(resp, r)
  70. }
  71. func (c *BucketService) ListAll(req BucketListAll) (*BucketListAllResp, error) {
  72. return JSONAPI(c.cfg, http.DefaultClient, &req, &BucketListAllResp{})
  73. }

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