Skip to content

Commit c0d9edc

Browse files
authored
Merge 2a918ad into 4c7e982
2 parents 4c7e982 + 2a918ad commit c0d9edc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+395
-280
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ runs:
7878
if: ${{ inputs.language == 'go' }}
7979
shell: bash
8080
run: |
81-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.3
81+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.5
8282
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
83-
go install golang.org/x/tools/cmd/[email protected]
8483
8584
- name: Cache golangci-lint analysis
8685
if: ${{ inputs.language == 'go' }}
Lines changed: 50 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,61 @@
1-
linters-settings:
2-
govet:
3-
enable-all: true
4-
disable:
5-
- fieldalignment
6-
7-
revive:
8-
rules:
9-
- name: var-naming
10-
disabled: true
11-
1+
version: "2"
2+
run:
3+
concurrency: 2
124
linters:
13-
enable-all: true
14-
5+
default: all
156
disable:
16-
- godox
17-
- bodyclose
18-
- contextcheck
19-
- interfacebloat
20-
- gci
21-
- gosmopolitan
22-
- wsl
23-
- varnamelen
24-
- nlreturn
7+
- canonicalheader
8+
- containedctx
9+
- copyloopvar
10+
- cyclop
11+
- depguard
12+
- dupl
13+
- dupword
2514
- err113
26-
- gochecknoglobals
27-
- exhaustruct
2815
- exhaustive
29-
- depguard
30-
- lll
16+
- exhaustruct
3117
- forbidigo
32-
- gochecknoinits
33-
- cyclop
34-
- errorlint
35-
- gomnd
36-
- tagliatelle
37-
- nilnil
38-
- stylecheck
39-
- musttag
40-
- errchkjson
41-
- nonamedreturns
42-
- inamedparam
43-
- ineffassign
44-
- dupword
45-
- nestif
46-
- goconst
4718
- funlen
48-
- dupl
49-
- unparam
19+
- gochecknoglobals
5020
- gocognit
51-
- forcetypeassert
52-
- wastedassign
21+
- goconst
5322
- gocyclo
54-
- maintidx
55-
- copyloopvar
23+
- inamedparam
5624
- intrange
57-
- canonicalheader
25+
- lll
26+
- maintidx
5827
- mnd
28+
- nestif
29+
- nilnil
30+
- nonamedreturns
5931
- perfsprint
60-
- containedctx
61-
62-
# Deprecated
63-
- execinquery
64-
- exportloopref
65-
66-
issues:
67-
exclude-generated: disable
68-
69-
run:
70-
concurrency: 2
71-
timeout: 10m
32+
- recvcheck
33+
- tagliatelle
34+
- varnamelen
35+
settings:
36+
govet:
37+
enable-all: true
38+
disable:
39+
- fieldalignment
40+
revive:
41+
rules:
42+
- name: var-naming
43+
disabled: true
44+
staticcheck:
45+
checks: ["all", "-ST1005"]
46+
exclusions:
47+
generated: disable
48+
presets:
49+
- comments
50+
- std-error-handling
51+
formatters:
52+
enable:
53+
- gofmt
54+
- gofumpt
55+
- goimports
56+
- golines
57+
settings:
58+
golines:
59+
max-len: 150
60+
exclusions:
61+
generated: disable

clients/algoliasearch-client-go/algolia/debug/debug.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func Display(input any) {
3030
if !debug {
3131
return
3232
}
33+
3334
start := time.Now()
35+
3436
var msg string
3537
switch v := input.(type) {
3638
case *http.Request:
@@ -40,6 +42,7 @@ func Display(input any) {
4042
default:
4143
msg = fmt.Sprintf("do not know how to display %#v", v)
4244
}
45+
4346
Println(msg)
4447
fmt.Printf("took %s\n", time.Since(start))
4548
}
@@ -52,6 +55,7 @@ func Printf(format string, a ...any) {
5255
if !debug {
5356
return
5457
}
58+
5559
msg := fmt.Sprintf(format, a...)
5660
fmt.Printf("> ALGOLIA DEBUG: %s", msg)
5761
}

clients/algoliasearch-client-go/algolia/debug/utils.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ func copyReadCloser(r io.ReadCloser) (io.ReadCloser, string) {
1616
if r == nil {
1717
return nil, ""
1818
}
19+
1920
data, err := io.ReadAll(r)
2021
_ = r.Close()
22+
2123
if err != nil {
2224
return nil, ""
2325
}
26+
2427
return io.NopCloser(bytes.NewReader(data)), string(data)
2528
}
2629

@@ -29,10 +32,12 @@ func decodeGzipContent(in string) (string, error) {
2932
if err != nil {
3033
return in, fmt.Errorf("cannot open content with gzip.Reader: %w", err)
3134
}
35+
3236
out, err := io.ReadAll(gr)
3337
if err != nil {
3438
return in, fmt.Errorf("cannot read content from gzip.Reader: %w", err)
3539
}
40+
3641
return string(out), nil
3742
}
3843

@@ -43,25 +48,24 @@ func extractBody(body io.ReadCloser, c compression.Compression) (io.ReadCloser,
4348

4449
reader, content := copyReadCloser(body)
4550

46-
switch c {
47-
case compression.GZIP:
51+
if c == compression.GZIP {
4852
decodedContent, err := decodeGzipContent(content)
4953
if err == nil {
5054
content = decodedContent
5155
}
52-
default:
53-
// Do nothing
5456
}
5557

5658
return reader, content
5759
}
5860

5961
func prettyPrintJSON(input string) string {
6062
var b bytes.Buffer
63+
6164
err := json.Indent(&b, []byte(input), "\t", " ")
6265
if err != nil {
6366
return input
6467
}
68+
6569
return strings.TrimSuffix(b.String(), "\n")
6670
}
6771

@@ -88,8 +92,10 @@ func debugRequest(req *http.Request) string {
8892
if strings.Contains(strings.ToLower(k), "algolia") {
8993
str = strings.Repeat("*", len(str))
9094
}
95+
9196
msg += fmt.Sprintf("\theader=%s:%q\n", k, str)
9297
}
98+
9399
msg += fmt.Sprintf("\tbody=\n\t%s\n", prettyPrintJSON(body))
94100

95101
return msg

clients/algoliasearch-client-go/algolia/errs/no_more_host_to_try_err.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ func NewNoMoreHostToTryError(errs ...error) *NoMoreHostToTryError {
1717
}
1818
}
1919

20-
func (e *NoMoreHostToTryError) IntermediateNetworkErrors() []error {
21-
return e.intermediateNetworkErrors
20+
func (n *NoMoreHostToTryError) IntermediateNetworkErrors() []error {
21+
return n.intermediateNetworkErrors
2222
}
2323

24-
func (e *NoMoreHostToTryError) Error() string {
25-
if len(e.intermediateNetworkErrors) > 0 {
26-
return fmt.Errorf("all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. %w", errors.Join(e.intermediateNetworkErrors...)).Error()
24+
func (n *NoMoreHostToTryError) Error() string {
25+
if len(n.intermediateNetworkErrors) > 0 {
26+
return fmt.Errorf("all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. %w", errors.Join(n.intermediateNetworkErrors...)).
27+
Error()
2728
}
29+
2830
return "all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. You can use 'ExposeIntermediateNetworkErrors: true' in the config to investigate."
2931
}
3032

clients/algoliasearch-client-go/algolia/transport/configuration.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
)
88

99
type Configuration struct {
10-
AppID string
11-
ApiKey string
12-
13-
Hosts []StatefulHost
10+
Requester Requester
1411
DefaultHeader map[string]string
12+
AppID string
13+
APIKey string
1514
UserAgent string
16-
Requester Requester
15+
Hosts []StatefulHost
1716
ReadTimeout time.Duration
1817
WriteTimeout time.Duration
1918
ConnectTimeout time.Duration

clients/algoliasearch-client-go/algolia/transport/requester.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func DefaultHTTPClient(connectTimeout *time.Duration) *http.Client {
4343
}
4444

4545
type Requester interface {
46-
Request(req *http.Request, timeout time.Duration, connectTimeout time.Duration) (*http.Response, error)
46+
Request(
47+
req *http.Request,
48+
timeout time.Duration,
49+
connectTimeout time.Duration,
50+
) (*http.Response, error)
4751
}
4852

4953
type defaultRequester struct {

clients/algoliasearch-client-go/algolia/transport/retry_strategy.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ type Host struct {
2828
}
2929

3030
type RetryStrategy struct {
31-
sync.RWMutex
3231
hosts []StatefulHost
3332
writeTimeout time.Duration
3433
readTimeout time.Duration
34+
sync.RWMutex
3535
}
3636

37-
func newRetryStrategy(hosts []StatefulHost, readTimeout, writeTimeout time.Duration) *RetryStrategy {
37+
func newRetryStrategy(
38+
hosts []StatefulHost,
39+
readTimeout, writeTimeout time.Duration,
40+
) *RetryStrategy {
3841
if readTimeout == 0 {
3942
readTimeout = DefaultReadTimeout
4043
}
@@ -75,7 +78,10 @@ func (s *RetryStrategy) GetTryableHosts(k call.Kind) []Host {
7578

7679
for _, h := range s.hosts {
7780
if !h.isDown && h.accept(k) {
78-
hosts = append(hosts, Host{h.scheme, h.host, time.Duration(h.retryCount+1) * baseTimeout})
81+
hosts = append(
82+
hosts,
83+
Host{h.scheme, h.host, time.Duration(h.retryCount+1) * baseTimeout},
84+
)
7985
}
8086
}
8187

@@ -86,7 +92,10 @@ func (s *RetryStrategy) GetTryableHosts(k call.Kind) []Host {
8692
for _, h := range s.hosts {
8793
if h.accept(k) {
8894
h.reset()
89-
hosts = append(hosts, Host{h.scheme, h.host, time.Duration(h.retryCount+1) * baseTimeout})
95+
hosts = append(
96+
hosts,
97+
Host{h.scheme, h.host, time.Duration(h.retryCount+1) * baseTimeout},
98+
)
9099
}
91100
}
92101

@@ -99,16 +108,19 @@ func (s *RetryStrategy) Decide(h Host, code int, err error) Outcome {
99108

100109
if err == nil && is2xx(code) {
101110
s.markUp(h)
111+
102112
return Success
103113
}
104114

105115
if isTimeoutError(err) {
106116
s.markTimeout(h)
117+
107118
return Retry
108119
}
109120

110-
if !(isZero(code) || is4xx(code) || is2xx(code)) || isNetworkError(err) {
121+
if (!isZero(code) && !is4xx(code) && !is2xx(code)) || isNetworkError(err) {
111122
s.markDown(h)
123+
112124
return Retry
113125
}
114126

@@ -119,6 +131,7 @@ func (s *RetryStrategy) markUp(host Host) {
119131
for _, h := range s.hosts {
120132
if h.host == host.host {
121133
h.markUp()
134+
122135
return
123136
}
124137
}
@@ -128,6 +141,7 @@ func (s *RetryStrategy) markTimeout(host Host) {
128141
for _, h := range s.hosts {
129142
if h.host == host.host {
130143
h.markTimeout()
144+
131145
return
132146
}
133147
}
@@ -137,6 +151,7 @@ func (s *RetryStrategy) markDown(host Host) {
137151
for _, h := range s.hosts {
138152
if h.host == host.host {
139153
h.markDown()
154+
140155
return
141156
}
142157
}
@@ -146,7 +161,8 @@ func isNetworkError(err error) bool {
146161
if err == nil {
147162
return false
148163
}
149-
_, ok := err.(net.Error)
164+
165+
_, ok := err.(net.Error) //nolint:errorlint
150166
// We need to ensure that the error is a net.Error but not a
151167
// context.DeadlineExceeded error (which is actually a net.Error), because
152168
// we do not want to consider context.DeadlineExceeded as an error.
@@ -157,6 +173,7 @@ func isTimeoutError(err error) bool {
157173
if err == nil {
158174
return false
159175
}
176+
160177
return strings.Contains(err.Error(), context.DeadlineExceeded.Error())
161178
}
162179

0 commit comments

Comments
 (0)