From 6998c3c387518ba8e06ceff00b10be583c95d6cd Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 7 Nov 2013 12:19:24 -0800 Subject: [PATCH] go fmt --- config.go | 2 +- container.go | 6 ++-- docker/docker.go | 2 +- engine/engine.go | 28 +++++++-------- engine/init_test.go | 10 +++--- engine/job.go | 58 +++++++++++++++---------------- namesgenerator/names-generator.go | 2 +- netlink/netlink_darwin.go | 2 -- utils/daemon.go | 2 +- utils/random.go | 2 +- utils/utils.go | 4 +-- utils/utils_test.go | 26 +++++++------- utils_test.go | 2 +- 13 files changed, 71 insertions(+), 75 deletions(-) diff --git a/config.go b/config.go index 40c47e692c..42ae23a90f 100644 --- a/config.go +++ b/config.go @@ -1,8 +1,8 @@ package docker import ( - "net" "github.com/dotcloud/docker/engine" + "net" ) // FIXME: separate runtime configuration from http api configuration diff --git a/container.go b/container.go index 50bf2ec674..8238628131 100644 --- a/container.go +++ b/container.go @@ -394,9 +394,9 @@ func (container *Container) Inject(file io.Reader, pth string) error { if _, err := os.Stat(path.Join(container.rwPath(), pth)); err == nil { // Since err is nil, the path could be stat'd and it exists return fmt.Errorf("%s exists", pth) - } else if ! os.IsNotExist(err) { + } else if !os.IsNotExist(err) { // Expect err might be that the file doesn't exist, so - // if it's some other error, return that. + // if it's some other error, return that. return err } @@ -1086,7 +1086,7 @@ func (container *Container) allocateNetwork() error { Gateway: manager.bridgeNetwork.IP, manager: manager, } - if iface !=nil && iface.IPNet.IP != nil { + if iface != nil && iface.IPNet.IP != nil { ipNum := ipToInt(iface.IPNet.IP) manager.ipAllocator.inUse[ipNum] = struct{}{} } else { diff --git a/docker/docker.go b/docker/docker.go index c500633a71..877e7f67d0 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -4,9 +4,9 @@ import ( "flag" "fmt" "github.com/dotcloud/docker" + "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/sysinit" "github.com/dotcloud/docker/utils" - "github.com/dotcloud/docker/engine" "log" "os" "strings" diff --git a/engine/engine.go b/engine/engine.go index 8d67242ca2..10cc077253 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -2,13 +2,12 @@ package engine import ( "fmt" - "os" - "log" - "runtime" "github.com/dotcloud/docker/utils" + "log" + "os" + "runtime" ) - type Handler func(*Job) string var globalHandlers map[string]Handler @@ -25,8 +24,8 @@ 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 + root string + handlers map[string]Handler } // New initializes a new engine managing the directory specified at `root`. @@ -56,8 +55,8 @@ func New(root string) (*Engine, error) { return nil, err } eng := &Engine{ - root: root, - handlers: globalHandlers, + root: root, + handlers: globalHandlers, } return eng, nil } @@ -66,12 +65,12 @@ func New(root string) (*Engine, error) { // 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 { @@ -79,4 +78,3 @@ func (eng *Engine) Job(name string, args ...string) *Job { } return job } - diff --git a/engine/init_test.go b/engine/init_test.go index 5c03ded87d..48d9009171 100644 --- a/engine/init_test.go +++ b/engine/init_test.go @@ -1,18 +1,18 @@ package engine import ( - "testing" + "fmt" + "github.com/dotcloud/docker/utils" + "io/ioutil" "runtime" "strings" - "fmt" - "io/ioutil" - "github.com/dotcloud/docker/utils" + "testing" ) var globalTestID string func init() { - Register("dummy", func(job *Job) string { return ""; }) + Register("dummy", func(job *Job) string { return "" }) } func mkEngine(t *testing.T) *Engine { diff --git a/engine/job.go b/engine/job.go index 0bde2a0beb..c2b14d55c2 100644 --- a/engine/job.go +++ b/engine/job.go @@ -1,11 +1,11 @@ package engine import ( + "encoding/json" + "fmt" + "github.com/dotcloud/docker/utils" "io" "strings" - "fmt" - "encoding/json" - "github.com/dotcloud/docker/utils" ) // A job is the fundamental unit of work in the docker engine. @@ -20,17 +20,17 @@ import ( // One slight variation is that jobs report their status as a string. The // string "0" indicates success, and any other strings indicates an error. // This allows for richer error reporting. -// +// type Job struct { - eng *Engine - Name string - Args []string - env []string - Stdin io.ReadCloser - Stdout io.WriteCloser - Stderr io.WriteCloser - handler func(*Job) string - status string + eng *Engine + Name string + Args []string + env []string + Stdin io.ReadCloser + Stdout io.WriteCloser + Stderr io.WriteCloser + handler func(*Job) string + status string } // Run executes the job and blocks until the job completes. @@ -57,21 +57,21 @@ func (job *Job) String() string { } func (job *Job) Getenv(key string) (value string) { - for _, kv := range job.env { - if strings.Index(kv, "=") == -1 { - continue - } - parts := strings.SplitN(kv, "=", 2) - if parts[0] != key { - continue - } - if len(parts) < 2 { - value = "" - } else { - value = parts[1] - } - } - return + for _, kv := range job.env { + if strings.Index(kv, "=") == -1 { + continue + } + parts := strings.SplitN(kv, "=", 2) + if parts[0] != key { + continue + } + if len(parts) < 2 { + value = "" + } else { + value = parts[1] + } + } + return } func (job *Job) GetenvBool(key string) (value bool) { @@ -109,5 +109,5 @@ func (job *Job) SetenvList(key string, value []string) error { } func (job *Job) Setenv(key, value string) { - job.env = append(job.env, key + "=" + value) + job.env = append(job.env, key+"="+value) } diff --git a/namesgenerator/names-generator.go b/namesgenerator/names-generator.go index 076bb1cba7..c0dd26830c 100644 --- a/namesgenerator/names-generator.go +++ b/namesgenerator/names-generator.go @@ -12,7 +12,7 @@ type NameChecker interface { var ( colors = [...]string{"white", "silver", "gray", "black", "blue", "green", "cyan", "yellow", "gold", "orange", "brown", "red", "violet", "pink", "magenta", "purple", "maroon", "crimson", "plum", "fuchsia", "lavender", "slate", "navy", "azure", "aqua", "olive", "teal", "lime", "beige", "tan", "sienna"} - animals = [...]string{"ant", "bear", "bird", "cat", "chicken", "cow", "deer", "dog", "donkey", "duck", "fish", "fox", "frog", "horse", "kangaroo", "koala", "lemur", "lion", "lizard", "monkey", "octopus", "pig", "shark", "sheep", "sloth", "spider", "squirrel", "tiger", "toad", "weasel", "whale", "wolf"} + animals = [...]string{"ant", "bear", "bird", "cat", "chicken", "cow", "deer", "dog", "donkey", "duck", "fish", "fox", "frog", "horse", "kangaroo", "koala", "lemur", "lion", "lizard", "monkey", "octopus", "pig", "shark", "sheep", "sloth", "spider", "squirrel", "tiger", "toad", "weasel", "whale", "wolf"} ) func GenerateRandomName(checker NameChecker) (string, error) { diff --git a/netlink/netlink_darwin.go b/netlink/netlink_darwin.go index becfb87759..9a972fe63f 100644 --- a/netlink/netlink_darwin.go +++ b/netlink/netlink_darwin.go @@ -9,7 +9,6 @@ func NetworkGetRoutes() ([]*net.IPNet, error) { return nil, fmt.Errorf("Not implemented") } - func NetworkLinkAdd(name string, linkType string) error { return fmt.Errorf("Not implemented") } @@ -18,7 +17,6 @@ func NetworkLinkUp(iface *net.Interface) error { return fmt.Errorf("Not implemented") } - func NetworkLinkAddIp(iface *net.Interface, ip net.IP, ipNet *net.IPNet) error { return fmt.Errorf("Not implemented") } diff --git a/utils/daemon.go b/utils/daemon.go index 179ff90e10..871122ed59 100644 --- a/utils/daemon.go +++ b/utils/daemon.go @@ -1,10 +1,10 @@ package utils import ( - "os" "fmt" "io/ioutil" "log" + "os" "strconv" ) diff --git a/utils/random.go b/utils/random.go index d5c37e44d0..d4d33c690a 100644 --- a/utils/random.go +++ b/utils/random.go @@ -1,9 +1,9 @@ package utils import ( - "io" "crypto/rand" "encoding/hex" + "io" ) func RandomString() string { diff --git a/utils/utils.go b/utils/utils.go index 4941eae42d..152c41d86c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,8 +15,8 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "regexp" + "runtime" "strconv" "strings" "sync" @@ -904,7 +904,7 @@ func StripComments(input []byte, commentMarker []byte) []byte { return output } -// GetNameserversAsCIDR returns nameservers (if any) listed in +// GetNameserversAsCIDR returns nameservers (if any) listed in // /etc/resolv.conf as CIDR blocks (e.g., "1.2.3.4/32") // This function's output is intended for net.ParseCIDR func GetNameserversAsCIDR(resolvConf []byte) []string { diff --git a/utils/utils_test.go b/utils/utils_test.go index f10bb40d3b..5377c181c4 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -453,20 +453,20 @@ search example.com`: {"1.2.3.4/32", "4.3.2.1/32"}, `search example.com`: {}, `nameserver 1.2.3.4 search example.com -nameserver 4.3.2.1`: []string{"1.2.3.4/32", "4.3.2.1/32"}, - ``: []string{}, - ` nameserver 1.2.3.4 `: []string{"1.2.3.4/32"}, - `search example.com +nameserver 4.3.2.1`: {"1.2.3.4/32", "4.3.2.1/32"}, + ``: {}, + ` nameserver 1.2.3.4 `: {"1.2.3.4/32"}, + `search example.com nameserver 1.2.3.4 -#nameserver 4.3.2.1`: []string{"1.2.3.4/32"}, - `search example.com -nameserver 1.2.3.4 # not 4.3.2.1`: []string{"1.2.3.4/32"}, - } { - test := GetNameserversAsCIDR([]byte(resolv)) - if !StrSlicesEqual(test, result) { - t.Fatalf("Wrong nameserver string {%s} should be %v. Input: %s", test, result, resolv) - } - } +#nameserver 4.3.2.1`: {"1.2.3.4/32"}, + `search example.com +nameserver 1.2.3.4 # not 4.3.2.1`: {"1.2.3.4/32"}, + } { + test := GetNameserversAsCIDR([]byte(resolv)) + if !StrSlicesEqual(test, result) { + t.Fatalf("Wrong nameserver string {%s} should be %v. Input: %s", test, result, resolv) + } + } } func StrSlicesEqual(a, b []string) bool { diff --git a/utils_test.go b/utils_test.go index 14cbd7c6be..87426f38ea 100644 --- a/utils_test.go +++ b/utils_test.go @@ -67,7 +67,7 @@ func newTestRuntime(prefix string) (runtime *Runtime, err error) { } config := &DaemonConfig{ - Root: root, + Root: root, AutoRestart: false, } runtime, err = NewRuntimeFromDirectory(config)