Skip to content

Commit 8c4c076

Browse files
authored
Add staticcheck (#1735)
Fix issues found (only costmetic) also deprecating ioutil. Make all constants have types.
1 parent 7e48272 commit 8c4c076

37 files changed

+142
-204
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ lint:
1616

1717
vet:
1818
@GO111MODULE=on go vet ./...
19+
@echo "Installing staticcheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
20+
${GOPATH}/bin/staticcheck -tests=false -checks="all,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022,-ST1023,-ST1005"
1921

2022
test:
2123
@GO111MODULE=on SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minio SECRET_KEY=minio123 ENABLE_HTTPS=1 MINT_MODE=full go test -race -v ./...

api-bucket-lifecycle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"bytes"
2222
"context"
2323
"encoding/xml"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"net/url"
2727

@@ -143,5 +143,5 @@ func (c *Client) getBucketLifecycle(ctx context.Context, bucketName string) ([]b
143143
}
144144
}
145145

146-
return ioutil.ReadAll(resp.Body)
146+
return io.ReadAll(resp.Body)
147147
}

api-bucket-policy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package minio
1818

1919
import (
2020
"context"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/url"
2424
"strings"
@@ -137,7 +137,7 @@ func (c *Client) getBucketPolicy(ctx context.Context, bucketName string) (string
137137
}
138138
}
139139

140-
bucketPolicyBuf, err := ioutil.ReadAll(resp.Body)
140+
bucketPolicyBuf, err := io.ReadAll(resp.Body)
141141
if err != nil {
142142
return "", err
143143
}

api-bucket-replication.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"context"
2323
"encoding/json"
2424
"encoding/xml"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"net/url"
2828
"time"
@@ -180,7 +180,7 @@ func (c *Client) GetBucketReplicationMetrics(ctx context.Context, bucketName str
180180
if resp.StatusCode != http.StatusOK {
181181
return s, httpRespToErrorResponse(resp, bucketName, "")
182182
}
183-
respBytes, err := ioutil.ReadAll(resp.Body)
183+
respBytes, err := io.ReadAll(resp.Body)
184184
if err != nil {
185185
return s, err
186186
}

api-bucket-tagging.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"encoding/xml"
2323
"errors"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
2726
"net/url"
2827

@@ -58,7 +57,7 @@ func (c *Client) GetBucketTagging(ctx context.Context, bucketName string) (*tags
5857
return nil, httpRespToErrorResponse(resp, bucketName, "")
5958
}
6059

61-
defer io.Copy(ioutil.Discard, resp.Body)
60+
defer io.Copy(io.Discard, resp.Body)
6261
return tags.ParseBucketXML(resp.Body)
6362
}
6463

api-compose-object.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"net/http"
2625
"net/url"
2726
"strconv"
@@ -516,7 +515,7 @@ func (c *Client) ComposeObject(ctx context.Context, dst CopyDestOptions, srcs ..
516515
return UploadInfo{}, err
517516
}
518517
if dst.Progress != nil {
519-
io.CopyN(ioutil.Discard, dst.Progress, end-start+1)
518+
io.CopyN(io.Discard, dst.Progress, end-start+1)
520519
}
521520
objParts = append(objParts, complPart)
522521
partIndex++

api-copy-object.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package minio
2020
import (
2121
"context"
2222
"io"
23-
"io/ioutil"
2423
"net/http"
2524
)
2625

@@ -54,7 +53,7 @@ func (c *Client) CopyObject(ctx context.Context, dst CopyDestOptions, src CopySr
5453

5554
// Update the progress properly after successful copy.
5655
if dst.Progress != nil {
57-
io.Copy(ioutil.Discard, io.LimitReader(dst.Progress, dst.Size))
56+
io.Copy(io.Discard, io.LimitReader(dst.Progress, dst.Size))
5857
}
5958

6059
cpObjRes := copyObjectResult{}

api-error-response.go

+1-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"encoding/xml"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
2726
)
2827

@@ -108,7 +107,7 @@ const (
108107
func xmlDecodeAndBody(bodyReader io.Reader, v interface{}) ([]byte, error) {
109108
// read the whole body (up to 1MB)
110109
const maxBodyLength = 1 << 20
111-
body, err := ioutil.ReadAll(io.LimitReader(bodyReader, maxBodyLength))
110+
body, err := io.ReadAll(io.LimitReader(bodyReader, maxBodyLength))
112111
if err != nil {
113112
return nil, err
114113
}
@@ -253,26 +252,6 @@ func errUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string)
253252
}
254253
}
255254

256-
// errInvalidBucketName - Invalid bucket name response.
257-
func errInvalidBucketName(message string) error {
258-
return ErrorResponse{
259-
StatusCode: http.StatusBadRequest,
260-
Code: "InvalidBucketName",
261-
Message: message,
262-
RequestID: "minio",
263-
}
264-
}
265-
266-
// errInvalidObjectName - Invalid object name response.
267-
func errInvalidObjectName(message string) error {
268-
return ErrorResponse{
269-
StatusCode: http.StatusNotFound,
270-
Code: "NoSuchKey",
271-
Message: message,
272-
RequestID: "minio",
273-
}
274-
}
275-
276255
// errInvalidArgument - Invalid argument response.
277256
func errInvalidArgument(message string) error {
278257
return ErrorResponse{

api-error-response_test.go

+3-31
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"bytes"
2222
"encoding/xml"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"reflect"
2727
"strconv"
@@ -57,7 +57,7 @@ func TestHttpRespToErrorResponse(t *testing.T) {
5757
resp := &http.Response{}
5858
resp.StatusCode = statusCode
5959
resp.Status = http.StatusText(statusCode)
60-
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
60+
resp.Body = io.NopCloser(bytes.NewBuffer(body))
6161
return resp
6262
}
6363

@@ -113,7 +113,7 @@ func TestHttpRespToErrorResponse(t *testing.T) {
113113
resp := &http.Response{
114114
StatusCode: statusCode,
115115
Status: http.StatusText(statusCode),
116-
Body: ioutil.NopCloser(bytes.NewReader(nil)),
116+
Body: io.NopCloser(bytes.NewReader(nil)),
117117
}
118118
setCommonHeaders(resp)
119119
return resp
@@ -243,34 +243,6 @@ func TestErrUnexpectedEOF(t *testing.T) {
243243
}
244244
}
245245

246-
// Test validates 'ErrInvalidBucketName' error response.
247-
func TestErrInvalidBucketName(t *testing.T) {
248-
expectedResult := ErrorResponse{
249-
StatusCode: http.StatusBadRequest,
250-
Code: "InvalidBucketName",
251-
Message: "Invalid Bucket name",
252-
RequestID: "minio",
253-
}
254-
actualResult := errInvalidBucketName("Invalid Bucket name")
255-
if !reflect.DeepEqual(expectedResult, actualResult) {
256-
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
257-
}
258-
}
259-
260-
// Test validates 'ErrInvalidObjectName' error response.
261-
func TestErrInvalidObjectName(t *testing.T) {
262-
expectedResult := ErrorResponse{
263-
StatusCode: http.StatusNotFound,
264-
Code: "NoSuchKey",
265-
Message: "Invalid Object Key",
266-
RequestID: "minio",
267-
}
268-
actualResult := errInvalidObjectName("Invalid Object Key")
269-
if !reflect.DeepEqual(expectedResult, actualResult) {
270-
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
271-
}
272-
}
273-
274246
// Test validates 'errInvalidArgument' response.
275247
func TestErrInvalidArgument(t *testing.T) {
276248
expectedResult := ErrorResponse{

api-get-object_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"crypto/rand"
2323
"io"
24-
"io/ioutil"
2524
"net/http"
2625
"net/http/httptest"
2726
"testing"
@@ -51,7 +50,7 @@ func TestGetObjectReturnSuccess(t *testing.T) {
5150
}
5251

5352
// We expect an error when reading back.
54-
buf, err := ioutil.ReadAll(obj)
53+
buf, err := io.ReadAll(obj)
5554
if err != nil {
5655
t.Fatalf("Expected 'nil', got %v", err)
5756
}
@@ -85,7 +84,7 @@ func TestGetObjectReturnErrorIfServerTruncatesResponse(t *testing.T) {
8584
}
8685

8786
// We expect an error when reading back.
88-
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
87+
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
8988
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
9089
}
9190
}
@@ -114,7 +113,7 @@ func TestGetObjectReturnErrorIfServerTruncatesResponseDouble(t *testing.T) {
114113
}
115114

116115
// We expect an error when reading back.
117-
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
116+
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
118117
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
119118
}
120119
}
@@ -143,7 +142,7 @@ func TestGetObjectReturnErrorIfServerSendsMore(t *testing.T) {
143142
}
144143

145144
// We expect an error when reading back.
146-
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
145+
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
147146
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
148147
}
149148
}

api-list.go

+2
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ func (c *Client) listMultipartUploadsQuery(ctx context.Context, bucketName, keyM
897897
}
898898

899899
// listObjectParts list all object parts recursively.
900+
//
901+
//lint:ignore U1000 Keep this around
900902
func (c *Client) listObjectParts(ctx context.Context, bucketName, objectName, uploadID string) (partsInfo map[int]ObjectPart, err error) {
901903
// Part number marker for the next batch of request.
902904
var nextPartNumberMarker int

api-put-object-multipart.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"fmt"
2727
"hash/crc32"
2828
"io"
29-
"io/ioutil"
3029
"net/http"
3130
"net/url"
3231
"sort"
@@ -412,7 +411,7 @@ func (c *Client) completeMultipartUpload(ctx context.Context, bucketName, object
412411

413412
// Read resp.Body into a []bytes to parse for Error response inside the body
414413
var b []byte
415-
b, err = ioutil.ReadAll(resp.Body)
414+
b, err = io.ReadAll(resp.Body)
416415
if err != nil {
417416
return UploadInfo{}, err
418417
}

api-putobject-snowball.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"context"
2525
"fmt"
2626
"io"
27-
"io/ioutil"
2827
"os"
2928
"strings"
3029
"sync"
@@ -107,7 +106,7 @@ func (c Client) PutObjectsSnowball(ctx context.Context, bucketName string, opts
107106
return nopReadSeekCloser{bytes.NewReader(b.Bytes())}, int64(b.Len()), nil
108107
}
109108
} else {
110-
f, err := ioutil.TempFile("", "s3-putsnowballobjects-*")
109+
f, err := os.CreateTemp("", "s3-putsnowballobjects-*")
111110
if err != nil {
112111
return err
113112
}

api-select.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type CSVFileHeaderInfo string
4141
// Constants for file header info.
4242
const (
4343
CSVFileHeaderInfoNone CSVFileHeaderInfo = "NONE"
44-
CSVFileHeaderInfoIgnore = "IGNORE"
45-
CSVFileHeaderInfoUse = "USE"
44+
CSVFileHeaderInfoIgnore CSVFileHeaderInfo = "IGNORE"
45+
CSVFileHeaderInfoUse CSVFileHeaderInfo = "USE"
4646
)
4747

4848
// SelectCompressionType - is the parameter for what type of compression is
@@ -52,15 +52,15 @@ type SelectCompressionType string
5252
// Constants for compression types under select API.
5353
const (
5454
SelectCompressionNONE SelectCompressionType = "NONE"
55-
SelectCompressionGZIP = "GZIP"
56-
SelectCompressionBZIP = "BZIP2"
55+
SelectCompressionGZIP SelectCompressionType = "GZIP"
56+
SelectCompressionBZIP SelectCompressionType = "BZIP2"
5757

5858
// Non-standard compression schemes, supported by MinIO hosts:
5959

60-
SelectCompressionZSTD = "ZSTD" // Zstandard compression.
61-
SelectCompressionLZ4 = "LZ4" // LZ4 Stream
62-
SelectCompressionS2 = "S2" // S2 Stream
63-
SelectCompressionSNAPPY = "SNAPPY" // Snappy stream
60+
SelectCompressionZSTD SelectCompressionType = "ZSTD" // Zstandard compression.
61+
SelectCompressionLZ4 SelectCompressionType = "LZ4" // LZ4 Stream
62+
SelectCompressionS2 SelectCompressionType = "S2" // S2 Stream
63+
SelectCompressionSNAPPY SelectCompressionType = "SNAPPY" // Snappy stream
6464
)
6565

6666
// CSVQuoteFields - is the parameter for how CSV fields are quoted.
@@ -69,7 +69,7 @@ type CSVQuoteFields string
6969
// Constants for csv quote styles.
7070
const (
7171
CSVQuoteFieldsAlways CSVQuoteFields = "Always"
72-
CSVQuoteFieldsAsNeeded = "AsNeeded"
72+
CSVQuoteFieldsAsNeeded CSVQuoteFields = "AsNeeded"
7373
)
7474

7575
// QueryExpressionType - is of what syntax the expression is, this should only
@@ -87,7 +87,7 @@ type JSONType string
8787
// Constants for JSONTypes.
8888
const (
8989
JSONDocumentType JSONType = "DOCUMENT"
90-
JSONLinesType = "LINES"
90+
JSONLinesType JSONType = "LINES"
9191
)
9292

9393
// ParquetInputOptions parquet input specific options
@@ -378,8 +378,8 @@ type SelectObjectType string
378378
// Constants for input data types.
379379
const (
380380
SelectObjectTypeCSV SelectObjectType = "CSV"
381-
SelectObjectTypeJSON = "JSON"
382-
SelectObjectTypeParquet = "Parquet"
381+
SelectObjectTypeJSON SelectObjectType = "JSON"
382+
SelectObjectTypeParquet SelectObjectType = "Parquet"
383383
)
384384

385385
// preludeInfo is used for keeping track of necessary information from the
@@ -416,7 +416,7 @@ type messageType string
416416

417417
const (
418418
errorMsg messageType = "error"
419-
commonMsg = "event"
419+
commonMsg messageType = "event"
420420
)
421421

422422
// eventType represents the type of event.
@@ -425,9 +425,9 @@ type eventType string
425425
// list of event-types returned by Select API.
426426
const (
427427
endEvent eventType = "End"
428-
recordsEvent = "Records"
429-
progressEvent = "Progress"
430-
statsEvent = "Stats"
428+
recordsEvent eventType = "Records"
429+
progressEvent eventType = "Progress"
430+
statsEvent eventType = "Stats"
431431
)
432432

433433
// contentType represents content type of event.

0 commit comments

Comments
 (0)