From 71977a841cd30eca711b18bf877db396d5a2460f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 15 Oct 2024 13:21:35 +0200 Subject: [PATCH] daemon: Daemon.registerName: inline validateID utility This function only checked for the ID to be non-empty, and was only used in a single location. Also move this check as first check in registerName, to allow for an early return. Signed-off-by: Sebastiaan van Stijn --- daemon/names.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/daemon/names.go b/daemon/names.go index 786979875284c..14cefc07fd9fd 100644 --- a/daemon/names.go +++ b/daemon/names.go @@ -20,11 +20,11 @@ var ( ) func (daemon *Daemon) registerName(container *container.Container) error { - if daemon.Exists(container.ID) { - return fmt.Errorf("Container is already loaded") + if container.ID == "" { + return fmt.Errorf("invalid empty id") } - if err := validateID(container.ID); err != nil { - return err + if daemon.Exists(container.ID) { + return fmt.Errorf("container is already loaded") } if container.Name == "" { name, err := daemon.generateAndReserveName(container.ID) @@ -106,10 +106,3 @@ func (daemon *Daemon) generateAndReserveName(id string) (string, error) { } return name, nil } - -func validateID(id string) error { - if id == "" { - return fmt.Errorf("Invalid empty id") - } - return nil -}