mirror of https://github.com/minio/minio.git
Code cleanup - simplify server side code. (#3870)
Fix all the issues reported by `gosimple` tool.
This commit is contained in:
parent
433225ab0d
commit
47ac410ab0
|
@ -1184,7 +1184,7 @@ func TestSetConfigHandler(t *testing.T) {
|
|||
t.Fatalf("Failed to decode set config result json %v", err)
|
||||
}
|
||||
|
||||
if result.Status != true {
|
||||
if !result.Status {
|
||||
t.Error("Expected set-config to succeed, but failed")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,10 +86,7 @@ func isBucketActionAllowed(action, bucket, prefix string) bool {
|
|||
resource := bucketARNPrefix + path.Join(bucket, prefix)
|
||||
var conditionKeyMap map[string]set.StringSet
|
||||
// Validate action, resource and conditions with current policy statements.
|
||||
if !bucketPolicyEvalStatements(action, resource, conditionKeyMap, policy.Statements) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return bucketPolicyEvalStatements(action, resource, conditionKeyMap, policy.Statements)
|
||||
}
|
||||
|
||||
// GetBucketLocationHandler - GET Bucket location.
|
||||
|
|
|
@ -209,10 +209,7 @@ func writeNotification(w http.ResponseWriter, notification map[string][]Notifica
|
|||
_, err = w.Write(append(notificationBytes, crlf...))
|
||||
// Make sure we have flushed, this would set Transfer-Encoding: chunked.
|
||||
w.(http.Flusher).Flush()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// CRLF character used for chunked transfer in accordance with HTTP standards.
|
||||
|
|
|
@ -213,9 +213,7 @@ func genFormatXLInvalidDisksOrder() []*formatConfigV1 {
|
|||
}
|
||||
// Re order jbod for failure case.
|
||||
var jbod1 = make([]string, 8)
|
||||
for i, j := range jbod {
|
||||
jbod1[i] = j
|
||||
}
|
||||
copy(jbod1, jbod)
|
||||
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
||||
formatConfigs[2].XL.JBOD = jbod1
|
||||
return formatConfigs
|
||||
|
@ -576,9 +574,7 @@ func TestSavedUUIDOrder(t *testing.T) {
|
|||
}
|
||||
// Re order jbod for failure case.
|
||||
var jbod1 = make([]string, 8)
|
||||
for i, j := range jbod {
|
||||
jbod1[i] = j
|
||||
}
|
||||
copy(jbod1, jbod)
|
||||
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
||||
formatConfigs[2].XL.JBOD = jbod1
|
||||
uuidTestCases[1].shouldPass = false
|
||||
|
|
|
@ -238,12 +238,9 @@ func saveFormatFS(formatPath string, fsFormat *formatConfigV1) error {
|
|||
}
|
||||
defer lk.Close()
|
||||
|
||||
if _, err = lk.Write(metadataBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = lk.Write(metadataBytes)
|
||||
// Success.
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Return if the part info in uploadedParts and completeParts are same.
|
||||
|
|
|
@ -67,12 +67,7 @@ func initMetaVolumeFS(fsPath, fsUUID string) error {
|
|||
}
|
||||
|
||||
metaMultipartPath := pathJoin(fsPath, minioMetaMultipartBucket)
|
||||
if err := mkdirAll(metaMultipartPath, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Return success here.
|
||||
return nil
|
||||
return mkdirAll(metaMultipartPath, 0777)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -98,10 +98,7 @@ func isWebhookQueue(sqsArn arnSQS) bool {
|
|||
return false
|
||||
}
|
||||
rNotify := serverConfig.Notify.GetWebhookByID(sqsArn.AccountID)
|
||||
if !rNotify.Enable {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return rNotify.Enable
|
||||
}
|
||||
|
||||
// Returns true if queueArn is for an Redis queue.
|
||||
|
|
|
@ -134,10 +134,7 @@ func isLocalStorage(ep *url.URL) bool {
|
|||
if globalMinioHost != "" && globalMinioPort != "" {
|
||||
// if --address host:port was specified for distXL we short
|
||||
// circuit only the endPoint that matches host:port
|
||||
if net.JoinHostPort(globalMinioHost, globalMinioPort) == ep.Host {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return net.JoinHostPort(globalMinioHost, globalMinioPort) == ep.Host
|
||||
}
|
||||
// Split host to extract host information.
|
||||
host, _, err := net.SplitHostPort(ep.Host)
|
||||
|
|
|
@ -243,7 +243,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||
if len(result.Objects) != 0 {
|
||||
c.Errorf("%s: Number of objects in the result different from expected value.", instanceType)
|
||||
}
|
||||
if result.IsTruncated != false {
|
||||
if result.IsTruncated {
|
||||
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||
if len(result.Objects) != i+1 {
|
||||
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, len(result.Objects), i+1)
|
||||
}
|
||||
if result.IsTruncated != false {
|
||||
if result.IsTruncated {
|
||||
c.Errorf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func testPaging(obj ObjectLayer, instanceType string, c TestErrHandler) {
|
|||
if len(result.Objects) != 5 {
|
||||
c.Errorf("%s: Expected length of objects to be %d, instead found to be %d", instanceType, 5, len(result.Objects))
|
||||
}
|
||||
if result.IsTruncated != true {
|
||||
if !result.IsTruncated {
|
||||
c.Errorf("%s: Expected IsTruncated to be `true`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||
}
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ func testListObjectsTestsForNonExistantBucket(obj ObjectLayer, instanceType stri
|
|||
if len(result.Objects) != 0 {
|
||||
c.Fatalf("%s: Expected number of objects in the result to be `%d`, but instead found `%d`", instanceType, 0, len(result.Objects))
|
||||
}
|
||||
if result.IsTruncated != false {
|
||||
if result.IsTruncated {
|
||||
c.Fatalf("%s: Expected IsTruncated to be `false`, but instead found it to be `%v`", instanceType, result.IsTruncated)
|
||||
}
|
||||
if err.Error() != "Bucket not found: bucket" {
|
||||
|
|
|
@ -569,7 +569,7 @@ func TestDoesV4PresignParamsExist(t *testing.T) {
|
|||
func TestParsePreSignV4(t *testing.T) {
|
||||
// converts the duration in seconds into string format.
|
||||
getDurationStr := func(expires int) string {
|
||||
return strconv.FormatInt(int64(expires), 10)
|
||||
return strconv.Itoa(expires)
|
||||
}
|
||||
// used in expected preSignValues, preSignValues.Date is of type time.Time .
|
||||
queryTime := time.Now().UTC()
|
||||
|
|
|
@ -1690,9 +1690,7 @@ func removeDiskN(disks []string, n int) {
|
|||
// Makes a entire new copy of a StorageAPI slice.
|
||||
func deepCopyStorageDisks(storageDisks []StorageAPI) []StorageAPI {
|
||||
newStorageDisks := make([]StorageAPI, len(storageDisks))
|
||||
for i, disk := range storageDisks {
|
||||
newStorageDisks[i] = disk
|
||||
}
|
||||
copy(newStorageDisks, storageDisks)
|
||||
return newStorageDisks
|
||||
}
|
||||
|
||||
|
|
|
@ -696,7 +696,7 @@ func testUploadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandler
|
|||
t.Fatalf("Failed, %v", err)
|
||||
}
|
||||
|
||||
if bytes.Compare(byteBuffer.Bytes(), content) != 0 {
|
||||
if !bytes.Equal(byteBuffer.Bytes(), content) {
|
||||
t.Fatalf("The upload file is different from the download file")
|
||||
}
|
||||
|
||||
|
@ -782,7 +782,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl
|
|||
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
||||
}
|
||||
|
||||
if bytes.Compare(bodyContent, content) != 0 {
|
||||
if !bytes.Equal(bodyContent, content) {
|
||||
t.Fatalf("The downloaded file is corrupted")
|
||||
}
|
||||
|
||||
|
@ -805,7 +805,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl
|
|||
t.Fatalf("Expected the response status to be 200, but instead found `%d`", code)
|
||||
}
|
||||
|
||||
if bytes.Compare(bodyContent, content) != 0 {
|
||||
if !bytes.Equal(bodyContent, content) {
|
||||
t.Fatalf("The downloaded file is corrupted")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ func (xl xlObjects) listObjectsHeal(bucket, prefix, marker, delimiter string, ma
|
|||
nextMarker = objInfo.Name
|
||||
objInfos = append(objInfos, objInfo)
|
||||
i++
|
||||
if walkResult.end == true {
|
||||
if walkResult.end {
|
||||
eof = true
|
||||
break
|
||||
}
|
||||
|
|
|
@ -161,12 +161,7 @@ func newXLObjects(storageDisks []StorageAPI) (ObjectLayer, error) {
|
|||
xl.writeQuorum = writeQuorum
|
||||
|
||||
// Do a quick heal on the buckets themselves for any discrepancies.
|
||||
if err := quickHeal(xl.storageDisks, xl.writeQuorum, xl.readQuorum); err != nil {
|
||||
return xl, err
|
||||
}
|
||||
|
||||
// Return successfully initialized object layer.
|
||||
return xl, nil
|
||||
return xl, quickHeal(xl.storageDisks, xl.writeQuorum, xl.readQuorum)
|
||||
}
|
||||
|
||||
// Shutdown function for object storage interface.
|
||||
|
|
Loading…
Reference in New Issue