Skip to content

Commit 8e5f477

Browse files
authored
Merge pull request #274 from fredbi/chore/linting-phase2
chore: relinting, continued
2 parents 1af6e90 + 42df208 commit 8e5f477

35 files changed

+196
-154
lines changed

bytestream.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ func ByteStreamConsumer(opts ...byteStreamOpt) Consumer {
5252
return errors.New("ByteStreamConsumer requires a reader") // early exit
5353
}
5454

55-
close := defaultCloser //nolint:revive,predeclared
55+
closer := defaultCloser
5656
if vals.Close {
5757
if cl, ok := reader.(io.Closer); ok {
58-
close = cl.Close //nolint:revive
58+
closer = cl.Close
5959
}
6060
}
61-
//nolint:errcheck // closing a reader wouldn't fail.
62-
defer close()
61+
defer func() {
62+
_ = closer()
63+
}()
6364

6465
if wrtr, ok := data.(io.Writer); ok {
6566
_, err := io.Copy(wrtr, reader)
@@ -109,14 +110,15 @@ func ByteStreamProducer(opts ...byteStreamOpt) Producer {
109110
if writer == nil {
110111
return errors.New("ByteStreamProducer requires a writer") // early exit
111112
}
112-
close := defaultCloser //nolint:revive,predeclared
113+
closer := defaultCloser
113114
if vals.Close {
114115
if cl, ok := writer.(io.Closer); ok {
115-
close = cl.Close //nolint:revive
116+
closer = cl.Close
116117
}
117118
}
118-
//nolint:errcheck // TODO: closing a writer would fail.
119-
defer close()
119+
defer func() {
120+
_ = closer()
121+
}()
120122

121123
if rc, ok := data.(io.ReadCloser); ok {
122124
defer rc.Close()

client/keepalive.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ func (d *drainingReadCloser) Close() error {
4848
// If the reader side (a HTTP server) is misbehaving, it still may send
4949
// some bytes, but the closer ignores them to keep the underling
5050
// connection open.
51-
//nolint:errcheck
52-
io.Copy(io.Discard, d.rdr)
51+
_, _ = io.Copy(io.Discard, d.rdr)
5352
}
5453
return d.rdr.Close()
5554
}

client/opentelemetry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func assertOpenTelemetrySubmit(t *testing.T, operation *runtime.ClientOperation,
121121
attribute.String("http.route", "/kubernetes-clusters/{cluster_id}"),
122122
attribute.String("http.method", http.MethodGet),
123123
attribute.String("span.kind", trace.SpanKindClient.String()),
124-
attribute.String("http.scheme", "https"),
124+
attribute.String("http.scheme", schemeHTTPS),
125125
// NOTE: this becomes http.response.status_code with semconv v1.21
126126
attribute.Int("http.status_code", 490),
127127
}, span.Attributes)

client/opentracing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type mockRuntime struct {
4242
func (m *mockRuntime) Submit(operation *runtime.ClientOperation) (interface{}, error) {
4343
_ = operation.Params.WriteToRequest(&m.req, nil)
4444
_, _ = operation.Reader.ReadResponse(&tres{}, nil)
45-
return nil, nil //nolint:nilnil
45+
return map[string]interface{}{}, nil
4646
}
4747

4848
func testOperation(ctx context.Context) *runtime.ClientOperation {
@@ -52,7 +52,7 @@ func testOperation(ctx context.Context) *runtime.ClientOperation {
5252
PathPattern: "/kubernetes-clusters/{cluster_id}",
5353
ProducesMediaTypes: []string{"application/json"},
5454
ConsumesMediaTypes: []string{"application/json"},
55-
Schemes: []string{"https"},
55+
Schemes: []string{schemeHTTPS},
5656
Reader: runtime.ClientResponseReaderFunc(func(runtime.ClientResponse, runtime.Consumer) (interface{}, error) {
5757
return nil, nil
5858
}),

client/request.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package client
1616

1717
import (
1818
"bytes"
19+
"context"
1920
"fmt"
2021
"io"
2122
"log"
@@ -317,13 +318,13 @@ DoneChoosingBodySource:
317318

318319
urlPath := path.Join(basePathURL.Path, pathPatternURL.Path)
319320
for k, v := range r.pathParams {
320-
urlPath = strings.Replace(urlPath, "{"+k+"}", url.PathEscape(v), -1) //nolint:gocritic
321+
urlPath = strings.ReplaceAll(urlPath, "{"+k+"}", url.PathEscape(v))
321322
}
322323
if reinstateSlash {
323-
urlPath = urlPath + "/" //nolint:gocritic
324+
urlPath += "/"
324325
}
325326

326-
req, err := http.NewRequest(r.method, urlPath, body) //nolint:noctx
327+
req, err := http.NewRequestWithContext(context.Background(), r.method, urlPath, body)
327328
if err != nil {
328329
return nil, err
329330
}
@@ -361,7 +362,7 @@ func (r *request) GetMethod() string {
361362
func (r *request) GetPath() string {
362363
path := r.pathPattern
363364
for k, v := range r.pathParams {
364-
path = strings.Replace(path, "{"+k+"}", v, -1) //nolint:gocritic
365+
path = strings.ReplaceAll(path, "{"+k+"}", v)
365366
}
366367
return path
367368
}

client/request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func TestGetBodyCallsBeforeRoundTrip(t *testing.T) {
769769
}),
770770
}
771771

772-
openAPIClient := New(hu.Host, "/", []string{"http"})
772+
openAPIClient := New(hu.Host, "/", []string{schemeHTTP})
773773
res, err := openAPIClient.Submit(operation)
774774
require.NoError(t, err)
775775

client/runtime.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//nolint:goconst
1615
package client
1716

1817
import (
@@ -40,6 +39,11 @@ import (
4039
"github.com/opentracing/opentracing-go"
4140
)
4241

42+
const (
43+
schemeHTTP = "http"
44+
schemeHTTPS = "https"
45+
)
46+
4347
// TLSClientOptions to configure client authentication with mutual TLS
4448
type TLSClientOptions struct {
4549
// Certificate is the path to a PEM-encoded certificate to be used for
@@ -112,7 +116,9 @@ type TLSClientOptions struct {
112116
// TLSClientAuth creates a tls.Config for mutual auth
113117
func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
114118
// create client tls config
115-
cfg := &tls.Config{} //nolint:gosec
119+
cfg := &tls.Config{
120+
MinVersion: tls.VersionTLS12,
121+
}
116122

117123
// load client cert if specified
118124
if opts.Certificate != "" {
@@ -158,11 +164,12 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
158164
// When no CA certificate is provided, default to the system cert pool
159165
// that way when a request is made to a server known by the system trust store,
160166
// the name is still verified
161-
if opts.LoadedCA != nil { //nolint:gocritic
167+
switch {
168+
case opts.LoadedCA != nil:
162169
caCertPool := basePool(opts.LoadedCAPool)
163170
caCertPool.AddCert(opts.LoadedCA)
164171
cfg.RootCAs = caCertPool
165-
} else if opts.CA != "" {
172+
case opts.CA != "":
166173
// load ca cert
167174
caCert, err := os.ReadFile(opts.CA)
168175
if err != nil {
@@ -171,7 +178,7 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
171178
caCertPool := basePool(opts.LoadedCAPool)
172179
caCertPool.AppendCertsFromPEM(caCert)
173180
cfg.RootCAs = caCertPool
174-
} else if opts.LoadedCAPool != nil {
181+
case opts.LoadedCAPool != nil:
175182
cfg.RootCAs = opts.LoadedCAPool
176183
}
177184

@@ -227,7 +234,7 @@ type Runtime struct {
227234
Host string
228235
BasePath string
229236
Formats strfmt.Registry
230-
Context context.Context //nolint:containedctx
237+
Context context.Context //nolint:containedctx // we precisely want this type to contain the request context
231238

232239
Debug bool
233240
logger logger.Logger
@@ -316,7 +323,7 @@ func (r *Runtime) pickScheme(schemes []string) string {
316323
if v := r.selectScheme(schemes); v != "" {
317324
return v
318325
}
319-
return "http"
326+
return schemeHTTP
320327
}
321328

322329
func (r *Runtime) selectScheme(schemes []string) string {
@@ -327,9 +334,9 @@ func (r *Runtime) selectScheme(schemes []string) string {
327334

328335
scheme := schemes[0]
329336
// prefer https, but skip when not possible
330-
if scheme != "https" && schLen > 1 {
337+
if scheme != schemeHTTPS && schLen > 1 {
331338
for _, sch := range schemes {
332-
if sch == "https" {
339+
if sch == schemeHTTPS {
333340
scheme = sch
334341
break
335342
}

0 commit comments

Comments
 (0)