return directly without ifs in remaining packages

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2016-12-14 23:16:12 +02:00
parent 8415aeb39a
commit 2c187a24e0
11 changed files with 16 additions and 52 deletions

View file

@ -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, err
}
return value, nil
} }
return def, nil return def, nil
} }

View file

@ -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 { _, err = io.Copy(w, data)
return err return err
}
return nil
} }
// // Encode the stat to JSON, base64 encode, and place in a header. // // Encode the stat to JSON, base64 encode, and place in a header.

View file

@ -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 print(writer, ctx, tasks, resolver, noTrunc)
return err
}
return nil
} }
// PrintQuiet shows task list in a quiet way. // PrintQuiet shows task list in a quiet way.

View file

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

View file

@ -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 { _, err = io.Copy(outStream, fs)
return err return err
}
return nil
} }
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) {

View file

@ -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 { err := json.NewDecoder(b).Decode(&pr)
return pr, err return pr, err
}
return pr, nil
} }
send := func(w http.ResponseWriter, data interface{}) { send := func(w http.ResponseWriter, data interface{}) {

View file

@ -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 string(b) != "N"
return false
}
return true
} }
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 root == ""
return false
}
return true
}, },
"Test cannot be run when remapping root", "Test cannot be run when remapping root",
} }

View file

@ -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 json.NewEncoder(f).Encode(mappings)
return err
}
return nil
} }
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 {

View file

@ -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 manager.reload()
return err
}
return nil
} }
// StateChanged updates plugin internals using libcontainerd events. // StateChanged updates plugin internals using libcontainerd events.

View file

@ -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 { _, _, err := ParseLink(val)
return val, err return val, err
}
return val, nil
} }
// ValidDeviceMode checks if the mode for device is valid or not. // ValidDeviceMode checks if the mode for device is valid or not.

View file

@ -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 used == hasRef
return true
}
return false
}) })
} }