From b4a7963c22a938e2f456c2a5d3111cf173ef8587 Mon Sep 17 00:00:00 2001 From: Sydonian <794346190@qq.com> Date: Tue, 10 Dec 2024 16:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=8Equery=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E5=BA=8F=E5=88=97=E5=8C=96=E7=94=A8=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdks/storage/cdsapi/storage_test.go | 17 +++++++++++++++++ utils/http2/http.go | 12 ++++++------ utils/http2/http_test.go | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sdks/storage/cdsapi/storage_test.go b/sdks/storage/cdsapi/storage_test.go index cec219e..e12f984 100644 --- a/sdks/storage/cdsapi/storage_test.go +++ b/sdks/storage/cdsapi/storage_test.go @@ -125,6 +125,23 @@ func Test_Object(t *testing.T) { }) } +func Test_ObjectList(t *testing.T) { + Convey("路径查询", t, func() { + cli := NewClient(&Config{ + URL: "http://localhost:7890", + }) + + resp, err := cli.Object().List(ObjectList{ + UserID: 1, + PackageID: 10, + Path: "100x100K/zexema", + }) + So(err, ShouldBeNil) + fmt.Printf("\n") + fmt.Printf("%+v\n", resp.Objects[0]) + }) +} + func Test_Storage(t *testing.T) { Convey("上传后调度文件", t, func() { cli := NewClient(&Config{ diff --git a/utils/http2/http.go b/utils/http2/http.go index 338f95c..ab67e21 100644 --- a/utils/http2/http.go +++ b/utils/http2/http.go @@ -385,7 +385,7 @@ func PostMultiPart(url string, param MultiPartRequestParam) (*http.Response, err defer muWriter.Close() if param.Form != nil { - mp, err := objectToStringMap(param.Form) + mp, err := objectToStringMap(param.Form, "json") if err != nil { return fmt.Errorf("formValues object to map failed, err: %w", err) } @@ -477,7 +477,7 @@ func prepareQuery(req *http.Request, query any) error { mp, ok := query.(map[string]string) if !ok { var err error - if mp, err = objectToStringMap(query); err != nil { + if mp, err = objectToStringMap(query, "form"); err != nil { return fmt.Errorf("query object to map: %w", err) } } @@ -499,7 +499,7 @@ func prepareHeader(req *http.Request, header any) error { mp, ok := header.(map[string]string) if !ok { var err error - if mp, err = objectToStringMap(header); err != nil { + if mp, err = objectToStringMap(header, "json"); err != nil { return fmt.Errorf("header object to map: %w", err) } } @@ -543,7 +543,7 @@ func prepareFormBody(req *http.Request, body any) error { mp, ok := body.(map[string]string) if !ok { var err error - if mp, err = objectToStringMap(body); err != nil { + if mp, err = objectToStringMap(body, "json"); err != nil { return fmt.Errorf("body object to map: %w", err) } } @@ -577,10 +577,10 @@ func setValue(values ul.Values, key, value string) ul.Values { return values } -func objectToStringMap(obj any) (map[string]string, error) { +func objectToStringMap(obj any, tag string) (map[string]string, error) { anyMap := make(map[string]any) dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - TagName: "json", + TagName: tag, Result: &anyMap, WeaklyTypedInput: true, }) diff --git a/utils/http2/http_test.go b/utils/http2/http_test.go index 85cef5f..d5922eb 100644 --- a/utils/http2/http_test.go +++ b/utils/http2/http_test.go @@ -21,7 +21,7 @@ func Test_objectToStringMap(t *testing.T) { Omit: nil, } - mp, err := objectToStringMap(a) + mp, err := objectToStringMap(a, "json") So(err, ShouldBeNil) So(mp, ShouldResemble, map[string]string{