From adf9a9d3007231a109cfc475df9f78a57e7566a1 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 15 Apr 2018 06:56:04 -0700 Subject: [PATCH] Remove all unused variables and functions (#5823) --- cmd/api-resources.go | 10 ---------- cmd/api-resources_test.go | 36 ----------------------------------- cmd/disk-cache-fs.go | 1 - cmd/format-disk-cache.go | 9 --------- cmd/format-disk-cache_test.go | 10 ++++++++++ cmd/fs-v1-metadata.go | 8 -------- cmd/globals.go | 1 - cmd/hasher.go | 6 ------ cmd/logger/logger.go | 5 ++--- cmd/test-utils_test.go | 5 +++++ cmd/utils.go | 13 ------------- cmd/utils_test.go | 12 ++++++++++++ cmd/xl-v1-utils.go | 11 ----------- pkg/handlers/proxy.go | 1 - 14 files changed, 29 insertions(+), 99 deletions(-) diff --git a/cmd/api-resources.go b/cmd/api-resources.go index fce7a517c..55ee0dcd3 100644 --- a/cmd/api-resources.go +++ b/cmd/api-resources.go @@ -78,13 +78,3 @@ func getObjectResources(values url.Values) (uploadID string, partNumberMarker, m encodingType = values.Get("encoding-type") return } - -// Validates filter values -func validateFilterValues(values []string) (err APIErrorCode) { - for _, value := range values { - if !IsValidObjectPrefix(value) { - return ErrFilterValueInvalid - } - } - return ErrNone -} diff --git a/cmd/api-resources_test.go b/cmd/api-resources_test.go index 4a43324d6..b76fb18ca 100644 --- a/cmd/api-resources_test.go +++ b/cmd/api-resources_test.go @@ -18,7 +18,6 @@ package cmd import ( "net/url" - "strings" "testing" ) @@ -189,38 +188,3 @@ func TestGetObjectsResources(t *testing.T) { } } } - -// Validates if filter values are correct -func TestValidateFilterValues(t *testing.T) { - testCases := []struct { - values []string - expectedError APIErrorCode - }{ - { - values: []string{""}, - expectedError: ErrNone, - }, - { - values: []string{"", "prefix"}, - expectedError: ErrNone, - }, - { - values: []string{strings.Repeat("a", 1025)}, - expectedError: ErrFilterValueInvalid, - }, - { - values: []string{"a\\b"}, - expectedError: ErrFilterValueInvalid, - }, - { - values: []string{string([]byte{0xff, 0xfe, 0xfd})}, - expectedError: ErrFilterValueInvalid, - }, - } - - for i, testCase := range testCases { - if actualError := validateFilterValues(testCase.values); actualError != testCase.expectedError { - t.Errorf("Test %d: Expected %d, got %d", i+1, testCase.expectedError, actualError) - } - } -} diff --git a/cmd/disk-cache-fs.go b/cmd/disk-cache-fs.go index 20ed5dbe4..e7702a6ff 100644 --- a/cmd/disk-cache-fs.go +++ b/cmd/disk-cache-fs.go @@ -37,7 +37,6 @@ import ( const ( // cache.json object metadata for cached objects. cacheMetaJSONFile = "cache.json" - cacheMetaFormat = "cache" cacheEnvDelimiter = ";" ) diff --git a/cmd/format-disk-cache.go b/cmd/format-disk-cache.go index 488073d77..bd94e22b8 100644 --- a/cmd/format-disk-cache.go +++ b/cmd/format-disk-cache.go @@ -87,15 +87,6 @@ func newFormatCacheV1(drives []string) []*formatCacheV1 { return formats } -// Returns format.Cache.Version -func formatCacheGetVersion(r io.ReadSeeker) (string, error) { - format := &formatCacheVersionDetect{} - if err := jsonLoad(r, format); err != nil { - return "", err - } - return format.Cache.Version, nil -} - // Creates a new cache format.json if unformatted. func createFormatCache(fsFormatPath string, format *formatCacheV1) error { // open file using READ & WRITE permission diff --git a/cmd/format-disk-cache_test.go b/cmd/format-disk-cache_test.go index eebadee47..89ee20a1c 100644 --- a/cmd/format-disk-cache_test.go +++ b/cmd/format-disk-cache_test.go @@ -18,10 +18,20 @@ package cmd import ( "context" + "io" "os" "testing" ) +// Returns format.Cache.Version +func formatCacheGetVersion(r io.ReadSeeker) (string, error) { + format := &formatCacheVersionDetect{} + if err := jsonLoad(r, format); err != nil { + return "", err + } + return format.Cache.Version, nil +} + // TestDiskCacheFormat - tests initFormatCache, formatMetaGetFormatBackendCache, formatCacheGetVersion. func TestDiskCacheFormat(t *testing.T) { ctx := context.Background() diff --git a/cmd/fs-v1-metadata.go b/cmd/fs-v1-metadata.go index 04c802a8c..f7727aee6 100644 --- a/cmd/fs-v1-metadata.go +++ b/cmd/fs-v1-metadata.go @@ -202,14 +202,6 @@ func parseFSVersion(fsMetaBuf []byte) string { return gjson.GetBytes(fsMetaBuf, "version").String() } -func parseFSFormat(fsMetaBuf []byte) string { - return gjson.GetBytes(fsMetaBuf, "format").String() -} - -func parseFSRelease(fsMetaBuf []byte) string { - return gjson.GetBytes(fsMetaBuf, "minio.release").String() -} - func parseFSMetaMap(fsMetaBuf []byte) map[string]string { // Get xlMetaV1.Meta map. metaMapResult := gjson.GetBytes(fsMetaBuf, "meta").Map() diff --git a/cmd/globals.go b/cmd/globals.go index 3d1f2d9d5..eb5f3a915 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -191,7 +191,6 @@ var ( colorBold = color.New(color.Bold).SprintFunc() colorBlue = color.New(color.FgBlue).SprintfFunc() colorYellow = color.New(color.FgYellow).SprintfFunc() - colorRed = color.New(color.FgRed).SprintfFunc() ) // Returns minio global information, as a key value map. diff --git a/cmd/hasher.go b/cmd/hasher.go index d38f319db..8762e5e1a 100644 --- a/cmd/hasher.go +++ b/cmd/hasher.go @@ -18,7 +18,6 @@ package cmd import ( "crypto/md5" - "encoding/base64" "encoding/hex" "github.com/minio/sha256-simd" @@ -47,8 +46,3 @@ func getMD5Sum(data []byte) []byte { func getMD5Hash(data []byte) string { return hex.EncodeToString(getMD5Sum(data)) } - -// getMD5HashBase64 returns MD5 hash in base64 encoding of given data. -func getMD5HashBase64(data []byte) string { - return base64.StdEncoding.EncodeToString(getMD5Sum(data)) -} diff --git a/cmd/logger/logger.go b/cmd/logger/logger.go index 159250eac..2da469bd5 100644 --- a/cmd/logger/logger.go +++ b/cmd/logger/logger.go @@ -33,9 +33,8 @@ import ( // global colors. var ( - colorBold = color.New(color.Bold).SprintFunc() - colorYellow = color.New(color.FgYellow).SprintfFunc() - colorRed = color.New(color.FgRed).SprintfFunc() + colorBold = color.New(color.Bold).SprintFunc() + colorRed = color.New(color.FgRed).SprintfFunc() ) var trimStrings []string diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 78ca4fb92..e2a802c67 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -1157,6 +1157,11 @@ func getCredentialString(accessKeyID, location string, t time.Time) string { return accessKeyID + "/" + getScope(t, location) } +// getMD5HashBase64 returns MD5 hash in base64 encoding of given data. +func getMD5HashBase64(data []byte) string { + return base64.StdEncoding.EncodeToString(getMD5Sum(data)) +} + // Returns new HTTP request object. func newTestRequest(method, urlStr string, contentLength int64, body io.ReadSeeker) (*http.Request, error) { if method == "" { diff --git a/cmd/utils.go b/cmd/utils.go index c39d4f3e9..7e6a184ff 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -23,7 +23,6 @@ import ( "encoding/base64" "encoding/json" "encoding/xml" - "errors" "fmt" "io" "net" @@ -232,18 +231,6 @@ func isFile(path string) bool { return false } -// checkURL - checks if passed address correspond -func checkURL(urlStr string) (*url.URL, error) { - if urlStr == "" { - return nil, errors.New("Address cannot be empty") - } - u, err := url.Parse(urlStr) - if err != nil { - return nil, fmt.Errorf("`%s` invalid: %s", urlStr, err.Error()) - } - return u, nil -} - // UTCNow - returns current UTC time. func UTCNow() time.Time { return time.Now().UTC() diff --git a/cmd/utils_test.go b/cmd/utils_test.go index 0e643fc90..071c4e1a6 100644 --- a/cmd/utils_test.go +++ b/cmd/utils_test.go @@ -233,6 +233,18 @@ func TestStartProfiler(t *testing.T) { } } +// checkURL - checks if passed address correspond +func checkURL(urlStr string) (*url.URL, error) { + if urlStr == "" { + return nil, errors.New("Address cannot be empty") + } + u, err := url.Parse(urlStr) + if err != nil { + return nil, fmt.Errorf("`%s` invalid: %s", urlStr, err.Error()) + } + return u, nil +} + // TestCheckURL tests valid url. func TestCheckURL(t *testing.T) { testCases := []struct { diff --git a/cmd/xl-v1-utils.go b/cmd/xl-v1-utils.go index 2e2b97817..5f5c914cb 100644 --- a/cmd/xl-v1-utils.go +++ b/cmd/xl-v1-utils.go @@ -369,17 +369,6 @@ func shuffleDisks(disks []StorageAPI, distribution []int) (shuffledDisks []Stora return shuffledDisks } -// unshuffleIndex - performs reverse of the shuffleDisks operations -// for a single 0-based index. -func unshuffleIndex(n int, distribution []int) int { - for i, v := range distribution { - if v-1 == n { - return i - } - } - return -1 -} - // evalDisks - returns a new slice of disks where nil is set if // the corresponding error in errs slice is not nil func evalDisks(disks []StorageAPI, errs []error) []StorageAPI { diff --git a/pkg/handlers/proxy.go b/pkg/handlers/proxy.go index 757ce64bc..b9cbc9d77 100644 --- a/pkg/handlers/proxy.go +++ b/pkg/handlers/proxy.go @@ -26,7 +26,6 @@ import ( var ( // De-facto standard header keys. xForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For") - xForwardedHost = http.CanonicalHeaderKey("X-Forwarded-Host") xForwardedProto = http.CanonicalHeaderKey("X-Forwarded-Proto") xForwardedScheme = http.CanonicalHeaderKey("X-Forwarded-Scheme") xRealIP = http.CanonicalHeaderKey("X-Real-IP")