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.

cache.go 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package stgsdk
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strings"
  6. "gitlink.org.cn/cloudream/common/consts/errorcode"
  7. myhttp "gitlink.org.cn/cloudream/common/utils/http"
  8. "gitlink.org.cn/cloudream/common/utils/serder"
  9. )
  10. type CacheMovePackageReq struct {
  11. UserID int64 `json:"userID"`
  12. PackageID int64 `json:"packageID"`
  13. NodeID int64 `json:"nodeID"`
  14. }
  15. type CacheMovePackageResp struct {
  16. CacheInfos []ObjectCacheInfo `json:"cacheInfos"`
  17. }
  18. func (c *Client) CacheMovePackage(req CacheMovePackageReq) (*CacheMovePackageResp, error) {
  19. url, err := url.JoinPath(c.baseURL, "/cache/movePackage")
  20. if err != nil {
  21. return nil, err
  22. }
  23. resp, err := myhttp.PostJSON(url, myhttp.RequestParam{
  24. Body: req,
  25. })
  26. if err != nil {
  27. return nil, err
  28. }
  29. contType := resp.Header.Get("Content-Type")
  30. if strings.Contains(contType, myhttp.ContentTypeJSON) {
  31. var codeResp response[CacheMovePackageResp]
  32. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  33. return nil, fmt.Errorf("parsing response: %w", err)
  34. }
  35. if codeResp.Code == errorcode.OK {
  36. return &codeResp.Data, nil
  37. }
  38. return nil, codeResp.ToError()
  39. }
  40. return nil, fmt.Errorf("unknow response content type: %s", contType)
  41. }