From e08a1c53aa5a19a17d40d41accbab040611c4411 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 11 Feb 2014 17:48:50 -0800 Subject: [PATCH] Move api-specific code to the api package This facilitates the refactoring of commands.go. Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- api/api.go | 9 +++++++++ docker/docker.go | 2 +- opts.go | 10 ---------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api/api.go b/api/api.go index 3bc8a8b504..e0077a94e3 100644 --- a/api/api.go +++ b/api/api.go @@ -27,6 +27,7 @@ import ( "syscall" ) +// FIXME: move code common to client and server to common.go const ( APIVERSION = 1.9 DEFAULTHTTPHOST = "127.0.0.1" @@ -34,6 +35,14 @@ const ( DEFAULTUNIXSOCKET = "/var/run/docker.sock" ) +func ValidateHost(val string) (string, error) { + host, err := utils.ParseHost(DEFAULTHTTPHOST, DEFAULTHTTPPORT, DEFAULTUNIXSOCKET, val) + if err != nil { + return val, err + } + return host, nil +} + type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error func init() { diff --git a/docker/docker.go b/docker/docker.go index d92f4d98ea..d2fe7c2596 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -42,7 +42,7 @@ func main() { flDefaultIp = flag.String([]string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports") flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication") flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver") - flHosts = docker.NewListOpts(docker.ValidateHost) + flHosts = docker.NewListOpts(api.ValidateHost) flMtu = flag.Int([]string{"#mtu", "-mtu"}, 0, "Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if not default route is available") ) flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers") diff --git a/opts.go b/opts.go index b1d71c491d..dffbcb404e 100644 --- a/opts.go +++ b/opts.go @@ -2,8 +2,6 @@ package docker import ( "fmt" - "github.com/dotcloud/docker/api" - "github.com/dotcloud/docker/utils" "os" "path/filepath" "regexp" @@ -129,14 +127,6 @@ func ValidateEnv(val string) (string, error) { return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil } -func ValidateHost(val string) (string, error) { - host, err := utils.ParseHost(api.DEFAULTHTTPHOST, api.DEFAULTHTTPPORT, api.DEFAULTUNIXSOCKET, val) - if err != nil { - return val, err - } - return host, nil -} - func ValidateIp4Address(val string) (string, error) { re := regexp.MustCompile(`^(([0-9]+\.){3}([0-9]+))\s*$`) var ns = re.FindSubmatch([]byte(val))