Upgrade linter and fix linter issues

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
This commit is contained in:
Bernd Verst 2022-11-11 13:19:57 -08:00
parent 9870c5e33b
commit 462e2faadc
12 changed files with 21 additions and 14 deletions

View File

@ -35,7 +35,7 @@ jobs:
GOOS: ${{ matrix.target_os }} GOOS: ${{ matrix.target_os }}
GOARCH: ${{ matrix.target_arch }} GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org GOPROXY: https://proxy.golang.org
GOLANGCI_LINT_VER: "v1.48.0" GOLANGCI_LINT_VER: "v1.50.1"
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]

View File

@ -277,3 +277,6 @@ linters:
- rowserrcheck - rowserrcheck
- sqlclosecheck - sqlclosecheck
- structcheck - structcheck
- deadcode
- nosnakecase
- varcheck

View File

@ -37,7 +37,7 @@ func TestPublishMsg(t *testing.T) { //nolint:paralleltest
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("{\"errcode\":0}")) _, err := w.Write([]byte("{\"errcode\":0}"))
require.NoError(t, err) require.NoError(t, err)
if r.Method != "POST" { if r.Method != http.MethodPost {
t.Errorf("Expected 'POST' request, got '%s'", r.Method) t.Errorf("Expected 'POST' request, got '%s'", r.Method)
} }
if r.URL.EscapedPath() != "/test" { if r.URL.EscapedPath() != "/test" {

View File

@ -196,7 +196,7 @@ func (g *GCPStorage) create(ctx context.Context, req *bindings.InvokeRequest) (*
func (g *GCPStorage) get(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) { func (g *GCPStorage) get(ctx context.Context, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error) {
metadata, err := g.metadata.mergeWithRequestMetadata(req) metadata, err := g.metadata.mergeWithRequestMetadata(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("gcp binding binding error. error merge metadata : %w", err) return nil, fmt.Errorf("gcp binding error. error merge metadata : %w", err)
} }
var key string var key string

View File

@ -28,7 +28,7 @@ import (
"github.com/dapr/kit/logger" "github.com/dapr/kit/logger"
) )
// Binding represents RethinkDB change change state input binding which fires handler with // Binding represents RethinkDB change state input binding which fires handler with
// both the previous and current state store content each time there is a change. // both the previous and current state store content each time there is a change.
type Binding struct { type Binding struct {
logger logger.Logger logger logger.Logger

View File

@ -126,7 +126,7 @@ func TestParseMetadata(t *testing.T) {
expectErr: true, expectErr: true,
}, },
{ {
desc: "Invalid metadata with missing tls client client", desc: "Invalid metadata with missing tls client",
input: pubsub.Metadata{Base: mdata.Base{ input: pubsub.Metadata{Base: mdata.Base{
Properties: map[string]string{ Properties: map[string]string{
"natsURL": "nats://localhost:4222", "natsURL": "nats://localhost:4222",

View File

@ -67,6 +67,8 @@ type rabbitMQ struct {
} }
// interface used to allow unit testing. // interface used to allow unit testing.
//
//nolint:interfacebloat
type rabbitMQChannelBroker interface { type rabbitMQChannelBroker interface {
PublishWithContext(ctx context.Context, exchange string, key string, mandatory bool, immediate bool, msg amqp.Publishing) error PublishWithContext(ctx context.Context, exchange string, key string, mandatory bool, immediate bool, msg amqp.Publishing) error
PublishWithDeferredConfirmWithContext(ctx context.Context, exchange string, key string, mandatory bool, immediate bool, msg amqp.Publishing) (*amqp.DeferredConfirmation, error) PublishWithDeferredConfirmWithContext(ctx context.Context, exchange string, key string, mandatory bool, immediate bool, msg amqp.Publishing) (*amqp.DeferredConfirmation, error)

View File

@ -185,11 +185,11 @@ func (k *keyvaultSecretStore) getVaultURI() string {
func (k *keyvaultSecretStore) getMaxResultsFromMetadata(metadata map[string]string) (*int32, error) { func (k *keyvaultSecretStore) getMaxResultsFromMetadata(metadata map[string]string) (*int32, error) {
if s, ok := metadata["maxresults"]; ok && s != "" { if s, ok := metadata["maxresults"]; ok && s != "" {
val, err := strconv.Atoi(s) //nolint:gosec val, err := strconv.Atoi(s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
converted := int32(val) converted := int32(val) //nolint:gosec
return &converted, nil return &converted, nil
} }

View File

@ -226,11 +226,11 @@ func (v *vaultSecretStore) getSecret(ctx context.Context, secret, version string
defer httpresp.Body.Close() defer httpresp.Body.Close()
if httpresp.StatusCode != 200 { if httpresp.StatusCode != http.StatusOK {
var b bytes.Buffer var b bytes.Buffer
io.Copy(&b, httpresp.Body) io.Copy(&b, httpresp.Body)
v.logger.Debugf("getSecret %s couldn't get successful response: %#v, %s", secret, httpresp, b.String()) v.logger.Debugf("getSecret %s couldn't get successful response: %#v, %s", secret, httpresp, b.String())
if httpresp.StatusCode == 404 { if httpresp.StatusCode == http.StatusNotFound {
// handle not found error // handle not found error
return nil, fmt.Errorf("getSecret %s failed %w", secret, ErrNotFound) return nil, fmt.Errorf("getSecret %s failed %w", secret, ErrNotFound)
} }
@ -344,7 +344,7 @@ func (v *vaultSecretStore) listKeysUnderPath(ctx context.Context, path string) (
defer httpresp.Body.Close() defer httpresp.Body.Close()
if httpresp.StatusCode != 200 { if httpresp.StatusCode != http.StatusOK {
var b bytes.Buffer var b bytes.Buffer
io.Copy(&b, httpresp.Body) io.Copy(&b, httpresp.Body)
v.logger.Debugf("list keys couldn't get successful response: %#v, %s", httpresp, b.String()) v.logger.Debugf("list keys couldn't get successful response: %#v, %s", httpresp, b.String())

View File

@ -18,6 +18,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"net/http"
"os" "os"
"path" "path"
"reflect" "reflect"
@ -405,7 +406,7 @@ func (c *ociObjectStorageClient) ensureBucketExists(ctx context.Context, client
// verify if bucket exists. // verify if bucket exists.
response, err := client.GetBucket(ctx, req) response, err := client.GetBucket(ctx, req)
if err != nil { if err != nil {
if response.RawResponse.StatusCode == 404 { if response.RawResponse.StatusCode == http.StatusNotFound {
err = createBucket(ctx, client, namespace, name, compartmentOCID) err = createBucket(ctx, client, namespace, name, compartmentOCID)
if err == nil { if err == nil {
c.logger.Debugf("Created OCI Object Storage Bucket %s as State Store", name) c.logger.Debugf("Created OCI Object Storage Bucket %s as State Store", name)
@ -445,7 +446,7 @@ func (c *ociObjectStorageClient) getObject(ctx context.Context, objectname strin
response, err := c.objectStorageMetadata.OCIObjectStorageClient.GetObject(ctx, request) response, err := c.objectStorageMetadata.OCIObjectStorageClient.GetObject(ctx, request)
if err != nil { if err != nil {
c.logger.Debugf("Issue in OCI ObjectStorage with retrieving object %s, error: %s", objectname, err) c.logger.Debugf("Issue in OCI ObjectStorage with retrieving object %s, error: %s", objectname, err)
if response.RawResponse.StatusCode == 404 { if response.RawResponse.StatusCode == http.StatusNotFound {
return nil, nil, nil, nil return nil, nil, nil, nil
} }
return nil, nil, nil, fmt.Errorf("failed to retrieve object : %w", err) return nil, nil, nil, fmt.Errorf("failed to retrieve object : %w", err)

View File

@ -277,6 +277,7 @@ func (m *migration) createStoredProcedureIfNotExists(db *sql.DB, name string, es
} }
/* #nosec. */ /* #nosec. */
//nolint:dupword
func (m *migration) ensureUpsertStoredProcedureExists(db *sql.DB, mr migrationResult) error { func (m *migration) ensureUpsertStoredProcedureExists(db *sql.DB, mr migrationResult) error {
tsql := fmt.Sprintf(` tsql := fmt.Sprintf(`
CREATE PROCEDURE %s ( CREATE PROCEDURE %s (

View File

@ -104,9 +104,9 @@ func appRouter() *mux.Router {
func handleCall(w http.ResponseWriter, r *http.Request) { func handleCall(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case "POST": case http.MethodPost:
s.handlePost(r) s.handlePost(r)
case "GET": case http.MethodGet:
w.Write(s.handleGet()) w.Write(s.handleGet())
default: default:
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)