From ae271e76451aa5e56f0a7c3de14e0abcdf9c7b84 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 14 Oct 2021 15:33:31 -0700 Subject: [PATCH] add new linters and fix unnecessary type conversions (#3835) --- .golangci.yml | 14 ++++++++++---- cmd/admin-info.go | 4 ++-- cmd/admin-policy-add.go | 2 +- cmd/admin-speedtest.go | 8 ++++---- cmd/admin-subnet-health.go | 2 +- cmd/admin-trace.go | 2 +- cmd/anonymous-main.go | 4 ++-- cmd/client-fs.go | 2 +- cmd/client-s3.go | 20 -------------------- cmd/client-s3_test.go | 8 ++++---- cmd/common-methods.go | 2 +- cmd/policy-main.go | 4 ++-- cmd/utils.go | 4 ++-- 13 files changed, 31 insertions(+), 45 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ef0fc09f..0e51416b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,21 +8,27 @@ linters-settings: linters: disable-all: true enable: - - revive - typecheck - goimports - misspell - govet + - revive - ineffassign - gosimple - deadcode - structcheck + - gomodguard + - gofmt + - unused + - structcheck + - varcheck issues: exclude-use-default: false exclude: - - instead of using struct literal - - should have a package comment - - error strings should not be capitalized or end with punctuation or a newline + - instead of using struct literal + - should have a package comment + - error strings should not be capitalized or end with punctuation or a newline + service: golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly diff --git a/cmd/admin-info.go b/cmd/admin-info.go index a0b753fa..6f84a6de 100644 --- a/cmd/admin-info.go +++ b/cmd/admin-info.go @@ -224,7 +224,7 @@ func (u clusterStruct) String() (msg string) { // Summary on used space, total no of buckets and // total no of objects at the Cluster level - usedTotal := humanize.IBytes(uint64(u.Info.Usage.Size)) + usedTotal := humanize.IBytes(u.Info.Usage.Size) if u.Info.Buckets.Count > 0 { msg += fmt.Sprintf("%s Used, %s, %s\n", usedTotal, english.Plural(int(u.Info.Buckets.Count), "Bucket", ""), @@ -281,7 +281,7 @@ func mainAdminInfo(ctx *cli.Context) error { clusterInfo.Error = "" } clusterInfo.Info = admInfo - printMsg(clusterStruct(clusterInfo)) + printMsg(clusterInfo) return nil } diff --git a/cmd/admin-policy-add.go b/cmd/admin-policy-add.go index 73ad13a7..d35ba5fe 100644 --- a/cmd/admin-policy-add.go +++ b/cmd/admin-policy-add.go @@ -134,7 +134,7 @@ func mainAdminPolicyAdd(ctx *cli.Context) error { client, err := newAdminClient(aliasedURL) fatalIf(err, "Unable to initialize admin connection.") - fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), []byte(policy))).Trace(args...), "Unable to add new policy") + fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), policy)).Trace(args...), "Unable to add new policy") printMsg(userPolicyMessage{ op: "add", diff --git a/cmd/admin-speedtest.go b/cmd/admin-speedtest.go index f7c95c43..8d90397f 100644 --- a/cmd/admin-speedtest.go +++ b/cmd/admin-speedtest.go @@ -86,10 +86,10 @@ func (s speedTestResult) String() (msg string) { if globalSpeedTestVerbose { msg += "\n" } - msg += fmt.Sprintf("PUT: %s/s, %d objs/s\n", humanize.IBytes(uint64(s.PUTStats.ThroughputPerSec)), s.PUTStats.ObjectsPerSec) + msg += fmt.Sprintf("PUT: %s/s, %d objs/s\n", humanize.IBytes(s.PUTStats.ThroughputPerSec), s.PUTStats.ObjectsPerSec) if globalSpeedTestVerbose { for _, node := range s.PUTStats.Servers { - msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(uint64(node.ThroughputPerSec)), node.ObjectsPerSec) + msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(node.ThroughputPerSec), node.ObjectsPerSec) if node.Err != "" { msg += " error: " + node.Err } @@ -100,10 +100,10 @@ func (s speedTestResult) String() (msg string) { if globalSpeedTestVerbose { msg += "\n" } - msg += fmt.Sprintf("GET: %s/s, %d objs/s\n", humanize.IBytes(uint64(s.GETStats.ThroughputPerSec)), s.GETStats.ObjectsPerSec) + msg += fmt.Sprintf("GET: %s/s, %d objs/s\n", humanize.IBytes(s.GETStats.ThroughputPerSec), s.GETStats.ObjectsPerSec) if globalSpeedTestVerbose { for _, node := range s.GETStats.Servers { - msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(uint64(node.ThroughputPerSec)), node.ObjectsPerSec) + msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(node.ThroughputPerSec), node.ObjectsPerSec) if node.Err != "" { msg += " error: " + node.Err } diff --git a/cmd/admin-subnet-health.go b/cmd/admin-subnet-health.go index 2b59f11b..528ed25b 100644 --- a/cmd/admin-subnet-health.go +++ b/cmd/admin-subnet-health.go @@ -321,7 +321,7 @@ func uploadHealthReport(alias string, filename string, reqURL string, headers ma } msg := "MinIO Health data was successfully uploaded to SUBNET." - clusterURL, _ := url.PathUnescape(gjson.Get(string(resp), "cluster_url").String()) + clusterURL, _ := url.PathUnescape(gjson.Get(resp, "cluster_url").String()) if len(clusterURL) > 0 { msg += fmt.Sprintf(" Can be viewed at: %s", clusterURL) } diff --git a/cmd/admin-trace.go b/cmd/admin-trace.go index 3b72480d..9cc5ae8c 100644 --- a/cmd/admin-trace.go +++ b/cmd/admin-trace.go @@ -478,7 +478,7 @@ func colorizedNodeName(nodeName string) string { nodeHash := fnv.New32a() nodeHash.Write([]byte(nodeName)) nHashSum := nodeHash.Sum32() - idx := uint32(nHashSum) % uint32(len(colors)) + idx := nHashSum % uint32(len(colors)) return console.Colorize(fmt.Sprintf("Node%d", colors[idx]), nodeName) } diff --git a/cmd/anonymous-main.go b/cmd/anonymous-main.go index e4155f9f..685e2dd9 100644 --- a/cmd/anonymous-main.go +++ b/cmd/anonymous-main.go @@ -164,7 +164,7 @@ type anonymousLinksMessage struct { // String colorized access message. func (s anonymousLinksMessage) String() string { - return console.Colorize("Anonymous", string(s.URL)) + return console.Colorize("Anonymous", s.URL) } // JSON jsonified anonymous message. @@ -203,7 +203,7 @@ func checkAnonymousSyntax(ctx *cli.Context) { accessPerms(secondArg) != accessPrivate && accessPerms(secondArg) != accessPublic { fatalIf(errDummy().Trace(), - "Unrecognized permission `"+string(secondArg)+"`. Allowed values are [private, public, download, upload].") + "Unrecognized permission `"+secondArg+"`. Allowed values are [private, public, download, upload].") } case "set-json": diff --git a/cmd/client-fs.go b/cmd/client-fs.go index ea3c30d8..e701089f 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -86,7 +86,7 @@ func isNotSupported(e error) bool { } // check if filesystem supports extended attributes - return errno.Err == syscall.Errno(syscall.ENOTSUP) || errno.Err == syscall.Errno(syscall.EOPNOTSUPP) + return errno.Err == syscall.ENOTSUP || errno.Err == syscall.EOPNOTSUPP } // isIgnoredFile returns true if 'filename' is on the exclude list. diff --git a/cmd/client-s3.go b/cmd/client-s3.go index 5978ec6a..6d518e49 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1900,26 +1900,6 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(ctx context.Context, content } } -// Convert objectMultipartInfo to ClientContent -func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio.ObjectMultipartInfo) ClientContent { - - content := ClientContent{} - url := c.targetURL.Clone() - // Join bucket and incoming object key. - url.Path = c.joinPath(bucket, entry.Key) - content.URL = url - content.Size = entry.Size - content.Time = entry.Initiated - - if strings.HasSuffix(entry.Key, string(c.targetURL.Separator)) { - content.Type = os.ModeDir - } else { - content.Type = os.ModeTemporary - } - - return content -} - // Returns new path by joining path segments with URL path separator. func (c *S3Client) joinPath(bucket string, objects ...string) string { p := string(c.targetURL.Separator) + bucket diff --git a/cmd/client-s3_test.go b/cmd/client-s3_test.go index d36d1499..70a2d9cf 100644 --- a/cmd/client-s3_test.go +++ b/cmd/client-s3_test.go @@ -158,9 +158,9 @@ func (h objectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Test bucket operations. func (s *TestSuite) TestBucketOperations(c *C) { - bucket := bucketHandler(bucketHandler{ + bucket := bucketHandler{ resource: "/bucket/", - }) + } server := httptest.NewServer(bucket) defer server.Close() @@ -205,10 +205,10 @@ func (s *TestSuite) TestBucketOperations(c *C) { // Test all object operations. func (s *TestSuite) TestObjectOperations(c *C) { - object := objectHandler(objectHandler{ + object := objectHandler{ resource: "/bucket/object", data: []byte("Hello, World"), - }) + } server := httptest.NewServer(object) defer server.Close() diff --git a/cmd/common-methods.go b/cmd/common-methods.go index 20baa630..6df66e17 100644 --- a/cmd/common-methods.go +++ b/cmd/common-methods.go @@ -576,7 +576,7 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader, md5: urls.MD5, disableMultipart: urls.DisableMultipart, isPreserve: preserve, - multipartSize: uint64(multipartSize), + multipartSize: multipartSize, multipartThreads: uint(multipartThreads), } diff --git a/cmd/policy-main.go b/cmd/policy-main.go index a72f9373..ecfc31f9 100644 --- a/cmd/policy-main.go +++ b/cmd/policy-main.go @@ -162,7 +162,7 @@ type policyLinksMessage struct { // String colorized access message. func (s policyLinksMessage) String() string { - return console.Colorize("Policy", string(s.URL)) + return console.Colorize("Policy", s.URL) } // JSON jsonified policy message. @@ -200,7 +200,7 @@ func checkPolicySyntax(ctx *cli.Context) { accessPerms(secondArg) != accessUpload && accessPerms(secondArg) != accessPublic { fatalIf(errDummy().Trace(), - "Unrecognized permission `"+string(secondArg)+"`. Allowed values are [none, download, upload, public].") + "Unrecognized permission `"+secondArg+"`. Allowed values are [none, download, upload, public].") } case "set-json": diff --git a/cmd/utils.go b/cmd/utils.go index ac63179b..449970a3 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -343,7 +343,7 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe return atime, mtime, probe.NewError(e) } } - atime = time.Unix(int64(atim), int64(atimnsec)) + atime = time.Unix(atim, atimnsec) } if val, ok := attr["mtime"]; ok { @@ -359,7 +359,7 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe return atime, mtime, probe.NewError(e) } } - mtime = time.Unix(int64(mtim), int64(mtimnsec)) + mtime = time.Unix(mtim, mtimnsec) } return atime, mtime, nil }