From 7848007c3ab41b3e1d733f9235a69ec59e04ead1 Mon Sep 17 00:00:00 2001 From: Yang Bai Date: Fri, 1 Nov 2013 09:42:44 +0800 Subject: [PATCH] rewrite protocol check with switch-case in Server.Daemon --- server.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server.go b/server.go index 815ed3fe7c..53e8da1317 100644 --- a/server.go +++ b/server.go @@ -6,10 +6,10 @@ import ( "errors" "fmt" "github.com/dotcloud/docker/auth" + "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/gograph" "github.com/dotcloud/docker/registry" "github.com/dotcloud/docker/utils" - "github.com/dotcloud/docker/engine" "io" "io/ioutil" "log" @@ -17,14 +17,14 @@ import ( "net/url" "os" "os/exec" + "os/signal" "path" "path/filepath" "runtime" "strings" "sync" - "time" "syscall" - "os/signal" + "time" ) func (srv *Server) Close() error { @@ -70,13 +70,16 @@ func (srv *Server) Daemon() error { chErrors := make(chan error, len(protoAddrs)) for _, protoAddr := range protoAddrs { protoAddrParts := strings.SplitN(protoAddr, "://", 2) - if protoAddrParts[0] == "unix" { - syscall.Unlink(protoAddrParts[1]) - } else if protoAddrParts[0] == "tcp" { + switch protoAddrParts[0] { + case "unix": + if err := syscall.Unlink(protoAddrParts[1]); err != nil && !os.IsNotExist(err) { + log.Fatal(err) + } + case "tcp": if !strings.HasPrefix(protoAddrParts[1], "127.0.0.1") { log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\") } - } else { + default: return fmt.Errorf("Invalid protocol format.") } go func() { @@ -92,7 +95,6 @@ func (srv *Server) Daemon() error { return nil } - func (srv *Server) DockerVersion() APIVersion { return APIVersion{ Version: VERSION,