From b00d5f018541bf141dc4732ad6d71d23b8c28b43 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 13 Nov 2013 19:25:55 +0000 Subject: [PATCH] gofmt --- engine/engine.go | 27 +++++++++++++-------------- engine/hack.go | 2 -- engine/job.go | 41 ++++++++++++++++++++++------------------- runtime_test.go | 6 +++--- server.go | 35 +++++++++++++++++------------------ server_test.go | 2 +- utils/utils_test.go | 18 +++++++++--------- utils_test.go | 3 +-- 8 files changed, 66 insertions(+), 68 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 09b599890b..edd04fc5c0 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -30,10 +30,10 @@ func Register(name string, handler Handler) error { // It acts as a store for *containers*, and allows manipulation of these // containers by executing *jobs*. type Engine struct { - root string - handlers map[string]Handler - hack Hack // data for temporary hackery (see hack.go) - id string + root string + handlers map[string]Handler + hack Hack // data for temporary hackery (see hack.go) + id string } func (eng *Engine) Root() string { @@ -50,7 +50,6 @@ func (eng *Engine) Register(name string, handler Handler) error { return nil } - // New initializes a new engine managing the directory specified at `root`. // `root` is used to store containers and any other state private to the engine. // Changing the contents of the root without executing a job will cause unspecified @@ -78,9 +77,9 @@ func New(root string) (*Engine, error) { return nil, err } eng := &Engine{ - root: root, - handlers: make(map[string]Handler), - id: utils.RandomString(), + root: root, + handlers: make(map[string]Handler), + id: utils.RandomString(), } // Copy existing global handlers for k, v := range globalHandlers { @@ -97,12 +96,12 @@ func (eng *Engine) String() string { // This function mimics `Command` from the standard os/exec package. func (eng *Engine) Job(name string, args ...string) *Job { job := &Job{ - Eng: eng, - Name: name, - Args: args, - Stdin: os.Stdin, - Stdout: os.Stdout, - Stderr: os.Stderr, + Eng: eng, + Name: name, + Args: args, + Stdin: os.Stdin, + Stdout: os.Stdout, + Stderr: os.Stderr, } handler, exists := eng.handlers[name] if exists { diff --git a/engine/hack.go b/engine/hack.go index 7f6e79c0e9..be4fadbe6e 100644 --- a/engine/hack.go +++ b/engine/hack.go @@ -1,9 +1,7 @@ package engine - type Hack map[string]interface{} - func (eng *Engine) Hack_GetGlobalVar(key string) interface{} { if eng.hack == nil { return nil diff --git a/engine/job.go b/engine/job.go index ed41f6c5c4..c4a2c3ef52 100644 --- a/engine/job.go +++ b/engine/job.go @@ -3,14 +3,14 @@ package engine import ( "bufio" "bytes" + "encoding/json" + "fmt" "io" "io/ioutil" + "os" "strconv" "strings" - "fmt" "sync" - "encoding/json" - "os" ) // A job is the fundamental unit of work in the docker engine. @@ -27,16 +27,16 @@ import ( // This allows for richer error reporting. // type Job struct { - Eng *Engine - Name string - Args []string - env []string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - handler func(*Job) string - status string - onExit []func() + Eng *Engine + Name string + Args []string + env []string + Stdin io.Reader + Stdout io.Writer + Stderr io.Writer + handler func(*Job) string + status string + onExit []func() } // Run executes the job and blocks until the job completes. @@ -106,30 +106,33 @@ func (job *Job) parseLines(src io.Reader, dst *[]string, limit int) { func (job *Job) StdoutParseString(dst *string) { lines := make([]string, 0, 1) job.StdoutParseLines(&lines, 1) - job.onExit = append(job.onExit, func() { if len(lines) >= 1 { *dst = lines[0] }}) + job.onExit = append(job.onExit, func() { + if len(lines) >= 1 { + *dst = lines[0] + } + }) } func (job *Job) StderrParseString(dst *string) { lines := make([]string, 0, 1) job.StderrParseLines(&lines, 1) - job.onExit = append(job.onExit, func() { *dst = lines[0]; }) + job.onExit = append(job.onExit, func() { *dst = lines[0] }) } func (job *Job) StdoutPipe() io.ReadCloser { r, w := io.Pipe() job.Stdout = w - job.onExit = append(job.onExit, func(){ w.Close() }) + job.onExit = append(job.onExit, func() { w.Close() }) return r } func (job *Job) StderrPipe() io.ReadCloser { r, w := io.Pipe() job.Stderr = w - job.onExit = append(job.onExit, func(){ w.Close() }) + job.onExit = append(job.onExit, func() { w.Close() }) return r } - func (job *Job) CallString() string { return fmt.Sprintf("%s(%s)", job.Name, strings.Join(job.Args, ", ")) } @@ -242,7 +245,7 @@ func (job *Job) DecodeEnv(src io.Reader) error { job.SetenvInt(k, int64(fval)) } else if sval, ok := v.(string); ok { job.Setenv(k, sval) - } else if val, err := json.Marshal(v); err == nil { + } else if val, err := json.Marshal(v); err == nil { job.Setenv(k, string(val)) } else { job.Setenv(k, fmt.Sprintf("%v", v)) diff --git a/runtime_test.go b/runtime_test.go index 886f107198..6a365d338d 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -9,6 +9,7 @@ import ( "io" "log" "net" + "net/url" "os" "path/filepath" "runtime" @@ -18,7 +19,6 @@ import ( "syscall" "testing" "time" - "net/url" ) const ( @@ -158,8 +158,8 @@ func spawnGlobalDaemon() { go func() { utils.Debugf("Spawning global daemon for integration tests") listenURL := &url.URL{ - Scheme: testDaemonProto, - Host: testDaemonAddr, + Scheme: testDaemonProto, + Host: testDaemonAddr, } job := eng.Job("serveapi", listenURL.String()) job.SetenvBool("Logging", os.Getenv("DEBUG") != "") diff --git a/server.go b/server.go index 66c898cbd8..28858d6f6b 100644 --- a/server.go +++ b/server.go @@ -74,7 +74,6 @@ func jobInitApi(job *engine.Job) string { return "0" } - func (srv *Server) ListenAndServe(job *engine.Job) string { protoAddrs := job.Args chErrors := make(chan error, len(protoAddrs)) @@ -1388,25 +1387,25 @@ func (srv *Server) ContainerStart(job *engine.Job) string { return err.Error() } // Validate the HostConfig binds. Make sure that: - // 1) the source of a bind mount isn't / - // The bind mount "/:/foo" isn't allowed. - // 2) Check that the source exists - // The source to be bind mounted must exist. - for _, bind := range hostConfig.Binds { - splitBind := strings.Split(bind, ":") - source := splitBind[0] + // 1) the source of a bind mount isn't / + // The bind mount "/:/foo" isn't allowed. + // 2) Check that the source exists + // The source to be bind mounted must exist. + for _, bind := range hostConfig.Binds { + splitBind := strings.Split(bind, ":") + source := splitBind[0] - // refuse to bind mount "/" to the container - if source == "/" { - return fmt.Sprintf("Invalid bind mount '%s' : source can't be '/'", bind) - } + // refuse to bind mount "/" to the container + if source == "/" { + return fmt.Sprintf("Invalid bind mount '%s' : source can't be '/'", bind) + } - // ensure the source exists on the host - _, err := os.Stat(source) - if err != nil && os.IsNotExist(err) { - return fmt.Sprintf("Invalid bind mount '%s' : source doesn't exist", bind) - } - } + // ensure the source exists on the host + _, err := os.Stat(source) + if err != nil && os.IsNotExist(err) { + return fmt.Sprintf("Invalid bind mount '%s' : source doesn't exist", bind) + } + } // Register any links from the host config before starting the container // FIXME: we could just pass the container here, no need to lookup by name again. if err := srv.RegisterLinks(name, &hostConfig); err != nil { diff --git a/server_test.go b/server_test.go index e9dba2eefc..1ab38422f5 100644 --- a/server_test.go +++ b/server_test.go @@ -2,8 +2,8 @@ package docker import ( "github.com/dotcloud/docker/utils" - "strings" "io/ioutil" + "strings" "testing" "time" ) diff --git a/utils/utils_test.go b/utils/utils_test.go index 09b15c73bc..350ebb911f 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -266,23 +266,23 @@ func TestHumanSize(t *testing.T) { } func TestRAMInBytes(t *testing.T) { - assertRAMInBytes(t, "32", false, 32) - assertRAMInBytes(t, "32b", false, 32) - assertRAMInBytes(t, "32B", false, 32) - assertRAMInBytes(t, "32k", false, 32*1024) - assertRAMInBytes(t, "32K", false, 32*1024) + assertRAMInBytes(t, "32", false, 32) + assertRAMInBytes(t, "32b", false, 32) + assertRAMInBytes(t, "32B", false, 32) + assertRAMInBytes(t, "32k", false, 32*1024) + assertRAMInBytes(t, "32K", false, 32*1024) assertRAMInBytes(t, "32kb", false, 32*1024) assertRAMInBytes(t, "32Kb", false, 32*1024) assertRAMInBytes(t, "32Mb", false, 32*1024*1024) assertRAMInBytes(t, "32Gb", false, 32*1024*1024*1024) - assertRAMInBytes(t, "", true, -1) + assertRAMInBytes(t, "", true, -1) assertRAMInBytes(t, "hello", true, -1) - assertRAMInBytes(t, "-32", true, -1) - assertRAMInBytes(t, " 32 ", true, -1) + assertRAMInBytes(t, "-32", true, -1) + assertRAMInBytes(t, " 32 ", true, -1) assertRAMInBytes(t, "32 mb", true, -1) assertRAMInBytes(t, "32m b", true, -1) - assertRAMInBytes(t, "32bm", true, -1) + assertRAMInBytes(t, "32bm", true, -1) } func assertRAMInBytes(t *testing.T, size string, expectError bool, expectedBytes int64) { diff --git a/utils_test.go b/utils_test.go index c3f282f169..a9678a9bbd 100644 --- a/utils_test.go +++ b/utils_test.go @@ -27,7 +27,7 @@ func mkRuntime(f utils.Fataler) *Runtime { f.Fatal(err) } config := &DaemonConfig{ - Root: root, + Root: root, AutoRestart: false, } r, err := NewRuntimeFromDirectory(config) @@ -66,7 +66,6 @@ func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *Server { return srv } - func NewTestEngine(t utils.Fataler) *engine.Engine { root, err := newTestDirectory(unitTestStoreBase) if err != nil {