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.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package storage
  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. func (c *Client) CacheMovePackage(req CacheMovePackageReq) error {
  16. url, err := url.JoinPath(c.baseURL, "/cache/movePackage")
  17. if err != nil {
  18. return err
  19. }
  20. resp, err := myhttp.PostJSON(url, myhttp.RequestParam{
  21. Body: req,
  22. })
  23. if err != nil {
  24. return err
  25. }
  26. contType := resp.Header.Get("Content-Type")
  27. if strings.Contains(contType, myhttp.ContentTypeJSON) {
  28. var codeResp response[any]
  29. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  30. return fmt.Errorf("parsing response: %w", err)
  31. }
  32. if codeResp.Code == errorcode.OK {
  33. return nil
  34. }
  35. return codeResp.ToError()
  36. }
  37. return fmt.Errorf("unknow response content type: %s", contType)
  38. }