Преглед изворни кода

return directly without ifs in remaining packages

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
unclejack пре 8 година
родитељ
комит
2c187a24e0

+ 1 - 4
api/server/httputils/form.go

@@ -38,10 +38,7 @@ func Int64ValueOrZero(r *http.Request, k string) int64 {
 func Int64ValueOrDefault(r *http.Request, field string, def int64) (int64, error) {
 func Int64ValueOrDefault(r *http.Request, field string, def int64) (int64, error) {
 	if r.Form.Get(field) != "" {
 	if r.Form.Get(field) != "" {
 		value, err := strconv.ParseInt(r.Form.Get(field), 10, 64)
 		value, err := strconv.ParseInt(r.Form.Get(field), 10, 64)
-		if err != nil {
-			return value, err
-		}
-		return value, nil
+		return value, err
 	}
 	}
 	return def, nil
 	return def, nil
 }
 }

+ 2 - 5
api/server/router/container/copy.go

@@ -50,11 +50,8 @@ func (s *containerRouter) postContainersCopy(ctx context.Context, w http.Respons
 	defer data.Close()
 	defer data.Close()
 
 
 	w.Header().Set("Content-Type", "application/x-tar")
 	w.Header().Set("Content-Type", "application/x-tar")
-	if _, err := io.Copy(w, data); err != nil {
-		return err
-	}
-
-	return nil
+	_, err = io.Copy(w, data)
+	return err
 }
 }
 
 
 // // Encode the stat to JSON, base64 encode, and place in a header.
 // // Encode the stat to JSON, base64 encode, and place in a header.

+ 1 - 5
cli/command/task/print.go

@@ -70,11 +70,7 @@ func Print(dockerCli *command.DockerCli, ctx context.Context, tasks []swarm.Task
 	defer writer.Flush()
 	defer writer.Flush()
 	fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR", "PORTS"}, "\t"))
 	fmt.Fprintln(writer, strings.Join([]string{"ID", "NAME", "IMAGE", "NODE", "DESIRED STATE", "CURRENT STATE", "ERROR", "PORTS"}, "\t"))
 
 
-	if err := print(writer, ctx, tasks, resolver, noTrunc); err != nil {
-		return err
-	}
-
-	return nil
+	return print(writer, ctx, tasks, resolver, noTrunc)
 }
 }
 
 
 // PrintQuiet shows task list in a quiet way.
 // PrintQuiet shows task list in a quiet way.

+ 1 - 6
cmd/dockerd/service_windows.go

@@ -219,12 +219,7 @@ func registerService() error {
 		return err
 		return err
 	}
 	}
 
 
-	err = eventlog.Install(*flServiceName, p, false, eventlog.Info|eventlog.Warning|eventlog.Error)
-	if err != nil {
-		return err
-	}
-
-	return nil
+	return eventlog.Install(*flServiceName, p, false, eventlog.Info|eventlog.Warning|eventlog.Error)
 }
 }
 
 
 func unregisterService() error {
 func unregisterService() error {

+ 2 - 4
image/tarexport/save.go

@@ -215,10 +215,8 @@ func (s *saveSession) save(outStream io.Writer) error {
 	}
 	}
 	defer fs.Close()
 	defer fs.Close()
 
 
-	if _, err := io.Copy(outStream, fs); err != nil {
-		return err
-	}
-	return nil
+	_, err = io.Copy(outStream, fs)
+	return err
 }
 }
 
 
 func (s *saveSession) saveImage(id image.ID) (map[layer.DiffID]distribution.Descriptor, error) {
 func (s *saveSession) saveImage(id image.ID) (map[layer.DiffID]distribution.Descriptor, error) {

+ 2 - 4
integration-cli/docker_cli_external_volume_driver_unix_test.go

@@ -103,10 +103,8 @@ func newVolumePlugin(c *check.C, name string) *volumePlugin {
 	read := func(b io.ReadCloser) (pluginRequest, error) {
 	read := func(b io.ReadCloser) (pluginRequest, error) {
 		defer b.Close()
 		defer b.Close()
 		var pr pluginRequest
 		var pr pluginRequest
-		if err := json.NewDecoder(b).Decode(&pr); err != nil {
-			return pr, err
-		}
-		return pr, nil
+		err := json.NewDecoder(b).Decode(&pr)
+		return pr, err
 	}
 	}
 
 
 	send := func(w http.ResponseWriter, data interface{}) {
 	send := func(w http.ResponseWriter, data interface{}) {

+ 2 - 8
integration-cli/requirements.go

@@ -180,10 +180,7 @@ var (
 				defer f.Close()
 				defer f.Close()
 				b := make([]byte, 1)
 				b := make([]byte, 1)
 				_, _ = f.Read(b)
 				_, _ = f.Read(b)
-				if string(b) == "N" {
-					return false
-				}
-				return true
+				return string(b) != "N"
 			}
 			}
 
 
 			return true
 			return true
@@ -193,10 +190,7 @@ var (
 	NotUserNamespace = testRequirement{
 	NotUserNamespace = testRequirement{
 		func() bool {
 		func() bool {
 			root := os.Getenv("DOCKER_REMAP_ROOT")
 			root := os.Getenv("DOCKER_REMAP_ROOT")
-			if root != "" {
-				return false
-			}
-			return true
+			return root == ""
 		},
 		},
 		"Test cannot be run when remapping root",
 		"Test cannot be run when remapping root",
 	}
 	}

+ 1 - 4
migrate/v1/migratev1.go

@@ -195,10 +195,7 @@ func saveMappings(root string, mappings map[string]image.ID) error {
 		return err
 		return err
 	}
 	}
 	defer f.Close()
 	defer f.Close()
-	if err := json.NewEncoder(f).Encode(mappings); err != nil {
-		return err
-	}
-	return nil
+	return json.NewEncoder(f).Encode(mappings)
 }
 }
 
 
 func migrateImages(root string, ls graphIDRegistrar, is image.Store, ms metadata.Store, mappings map[string]image.ID) error {
 func migrateImages(root string, ls graphIDRegistrar, is image.Store, ms metadata.Store, mappings map[string]image.ID) error {

+ 1 - 4
plugin/manager.go

@@ -79,10 +79,7 @@ func Init(root string, ps *store.Store, remote libcontainerd.Remote, rs registry
 		return err
 		return err
 	}
 	}
 	manager.cMap = make(map[*v2.Plugin]*controller)
 	manager.cMap = make(map[*v2.Plugin]*controller)
-	if err := manager.reload(); err != nil {
-		return err
-	}
-	return nil
+	return manager.reload()
 }
 }
 
 
 // StateChanged updates plugin internals using libcontainerd events.
 // StateChanged updates plugin internals using libcontainerd events.

+ 2 - 4
runconfig/opts/parse.go

@@ -859,10 +859,8 @@ func ParseLink(val string) (string, string, error) {
 
 
 // ValidateLink validates that the specified string has a valid link format (containerName:alias).
 // ValidateLink validates that the specified string has a valid link format (containerName:alias).
 func ValidateLink(val string) (string, error) {
 func ValidateLink(val string) (string, error) {
-	if _, _, err := ParseLink(val); err != nil {
-		return val, err
-	}
-	return val, nil
+	_, _, err := ParseLink(val)
+	return val, err
 }
 }
 
 
 // ValidDeviceMode checks if the mode for device is valid or not.
 // ValidDeviceMode checks if the mode for device is valid or not.

+ 1 - 4
volume/store/store.go

@@ -623,10 +623,7 @@ func (s *VolumeStore) FilterByUsed(vols []volume.Volume, used bool) []volume.Vol
 		s.locks.Lock(v.Name())
 		s.locks.Lock(v.Name())
 		hasRef := s.hasRef(v.Name())
 		hasRef := s.hasRef(v.Name())
 		s.locks.Unlock(v.Name())
 		s.locks.Unlock(v.Name())
-		if used == hasRef {
-			return true
-		}
-		return false
+		return used == hasRef
 	})
 	})
 }
 }