From e10ce291009340fe4af8f351bdf253da247fba72 Mon Sep 17 00:00:00 2001 From: vasilesk Date: Wed, 3 Apr 2024 21:25:04 +0300 Subject: [PATCH 1/3] add UnmarshalJSON for InputFileString --- models/input_file.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/input_file.go b/models/input_file.go index d42cc7b..f75dd63 100644 --- a/models/input_file.go +++ b/models/input_file.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "io" ) @@ -31,3 +32,7 @@ func (InputFileString) inputFileTag() {} func (i *InputFileString) MarshalJSON() ([]byte, error) { return []byte(`"` + i.Data + `"`), nil } + +func (i *InputFileString) UnmarshalJSON(data []byte) error { + return json.Unmarshal(data, &i.Data) +} From a2a6f03bb6747b65b554664292893de1430b1e93 Mon Sep 17 00:00:00 2001 From: vasilesk Date: Thu, 4 Apr 2024 21:51:45 +0300 Subject: [PATCH 2/3] pointer recievers for inputFile implementations --- models/input_file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/input_file.go b/models/input_file.go index f75dd63..2c49253 100644 --- a/models/input_file.go +++ b/models/input_file.go @@ -17,7 +17,7 @@ type InputFileUpload struct { Data io.Reader } -func (InputFileUpload) inputFileTag() {} +func (*InputFileUpload) inputFileTag() {} func (i *InputFileUpload) MarshalJSON() ([]byte, error) { return []byte(`"@` + i.Filename + `"`), nil @@ -27,7 +27,7 @@ type InputFileString struct { Data string } -func (InputFileString) inputFileTag() {} +func (*InputFileString) inputFileTag() {} func (i *InputFileString) MarshalJSON() ([]byte, error) { return []byte(`"` + i.Data + `"`), nil From 7e958df383031f1b0b4b86209eeaca49ae00396d Mon Sep 17 00:00:00 2001 From: vasilesk Date: Sat, 6 Apr 2024 18:18:12 +0300 Subject: [PATCH 3/3] fix test --- methods_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/methods_test.go b/methods_test.go index 725d1fa..5a7bfd3 100644 --- a/methods_test.go +++ b/methods_test.go @@ -230,11 +230,11 @@ func TestBot_Methods(t *testing.T) { t.Run("SendVideoNote", func(t *testing.T) { c := &httpClient{t: t, resp: `{"text":"bar"}`, reqFields: map[string]string{ - "thumbnail": `{"Data":"foo"}`, + "thumbnail": `foo`, }} b := &Bot{client: c} resp, err := b.SendVideoNote(context.Background(), &SendVideoNoteParams{ - Thumbnail: models.InputFileString{Data: "foo"}, + Thumbnail: &models.InputFileString{Data: "foo"}, }) assertNoErr(t, err) assertEqualString(t, "bar", resp.Text)