Skip to content

Commit c871f27

Browse files
authored
Tweaks (#159)
1 parent 847f957 commit c871f27

File tree

5 files changed

+7
-23
lines changed

5 files changed

+7
-23
lines changed

client.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"net/http"
1616
"net/textproto"
1717
"os"
18-
"strings"
1918
"time"
2019

2120
"github.com/golang-jwt/jwt/v4"
@@ -111,12 +110,6 @@ func (c *Client) VerifyWebhook(body, signature []byte) (valid bool) {
111110
return bytes.Equal(signature, []byte(expectedMAC))
112111
}
113112

114-
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
115-
116-
func escapeQuotes(s string) string {
117-
return quoteEscaper.Replace(s)
118-
}
119-
120113
// this makes possible to set content type.
121114
type multipartForm struct {
122115
*multipart.Writer
@@ -128,8 +121,7 @@ func (form *multipartForm) CreateFormFile(fieldName, filename, contentType strin
128121
h := make(textproto.MIMEHeader)
129122

130123
h.Set("Content-Disposition",
131-
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
132-
escapeQuotes(fieldName), escapeQuotes(filename)))
124+
fmt.Sprintf(`form-data; name=%q; filename=%q`, fieldName, filename))
133125

134126
if contentType == "" {
135127
contentType = "application/octet-stream"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/GetStream/stream-chat-go/v3
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/davecgh/go-spew v1.1.1 // indirect

http.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net/http"
1211
"net/url"
1312
)
@@ -38,7 +37,7 @@ func (c *Client) parseResponse(resp *http.Response, result interface{}) error {
3837
return errors.New("http body is nil")
3938
}
4039

41-
b, err := ioutil.ReadAll(resp.Body)
40+
b, err := io.ReadAll(resp.Body)
4241
if err != nil {
4342
return fmt.Errorf("failed to read HTTP response: %w", err)
4443
}
@@ -95,7 +94,7 @@ func (c *Client) newRequest(ctx context.Context, method, path string, params url
9594
return nil, err
9695
}
9796

98-
r, err := http.NewRequestWithContext(ctx, method, u, nil)
97+
r, err := http.NewRequestWithContext(ctx, method, u, http.NoBody)
9998
if err != nil {
10099
return nil, err
101100
}
@@ -109,14 +108,14 @@ func (c *Client) newRequest(ctx context.Context, method, path string, params url
109108
r.Body = t
110109

111110
case io.Reader:
112-
r.Body = ioutil.NopCloser(t)
111+
r.Body = io.NopCloser(t)
113112

114113
default:
115114
b, err := json.Marshal(data)
116115
if err != nil {
117116
return nil, err
118117
}
119-
r.Body = ioutil.NopCloser(bytes.NewReader(b))
118+
r.Body = io.NopCloser(bytes.NewReader(b))
120119
}
121120

122121
return r, nil

query_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,4 @@ func TestClient_QueryMessageFlags(t *testing.T) {
292292
})
293293
require.NoError(t, err)
294294
assert.Len(t, got.Flags, 1)
295-
296-
// none should show up
297-
got, err = c.QueryMessageFlags(context.Background(), &QueryOption{
298-
Filter: map[string]interface{}{"channel_cid": ch.cid()},
299-
})
300-
require.NoError(t, err)
301-
assert.Len(t, got.Flags, 0)
302295
}

run-lint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gopath="$(go env GOPATH)"
99
if ! [[ -x "$gopath/bin/golangci-lint" ]]; then
1010
echo >&2 'Installing golangci-lint'
1111
curl --silent --fail --location \
12-
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$gopath/bin" v1.42.0
12+
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$gopath/bin" v1.43.0
1313
fi
1414

1515
# configured by .golangci.yml

0 commit comments

Comments
 (0)