From 94cefa21459a0c620e5a9c2da04df6d3a43dae17 Mon Sep 17 00:00:00 2001 From: wangguoliang Date: Wed, 6 Sep 2017 16:54:24 +0800 Subject: [PATCH] Optimize some wrong usage and spelling Signed-off-by: wgliang --- api/types/client.go | 2 +- daemon/attach.go | 2 +- daemon/daemon.go | 2 +- daemon/graphdriver/graphtest/testutil.go | 8 ++++---- daemon/graphdriver/lcow/lcow.go | 16 ++++++++-------- daemon/kill.go | 2 +- daemon/stop.go | 2 +- .../agent/master/call.go | 6 +++--- .../agent/worker/worker.go | 2 +- integration-cli/docker_cli_cp_utils_test.go | 4 +--- integration-cli/docker_cli_events_test.go | 2 +- integration-cli/fixtures/plugin/plugin.go | 2 +- pkg/devicemapper/devmapper_log.go | 2 +- 13 files changed, 25 insertions(+), 27 deletions(-) diff --git a/api/types/client.go b/api/types/client.go index 18a1263f10..4ca9ccac72 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -181,7 +181,7 @@ type ImageBuildOptions struct { SessionID string // TODO @jhowardmsft LCOW Support: This will require extending to include - // `Platform string`, but is ommited for now as it's hard-coded temporarily + // `Platform string`, but is omitted for now as it's hard-coded temporarily // to avoid API changes. } diff --git a/daemon/attach.go b/daemon/attach.go index 7b676ccaf0..651a964c05 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -168,7 +168,7 @@ func (daemon *Daemon) containerAttach(c *container.Container, cfg *stream.Attach // Wait for the container to stop before returning. waitChan := c.Wait(context.Background(), container.WaitConditionNotRunning) defer func() { - _ = <-waitChan // Ignore returned exit code. + <-waitChan // Ignore returned exit code. }() } diff --git a/daemon/daemon.go b/daemon/daemon.go index a11a1f8691..2fcb9ed3ae 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -860,7 +860,7 @@ func (daemon *Daemon) shutdownContainer(c *container.Container) error { // Wait without timeout for the container to exit. // Ignore the result. - _ = <-c.Wait(context.Background(), container.WaitConditionNotRunning) + <-c.Wait(context.Background(), container.WaitConditionNotRunning) return nil } diff --git a/daemon/graphdriver/graphtest/testutil.go b/daemon/graphdriver/graphtest/testutil.go index 35bf6d17ba..40f8f554f0 100644 --- a/daemon/graphdriver/graphtest/testutil.go +++ b/daemon/graphdriver/graphtest/testutil.go @@ -61,7 +61,7 @@ func checkFile(drv graphdriver.Driver, layer, filename string, content []byte) e return err } - if bytes.Compare(fileContent, content) != 0 { + if !bytes.Equal(fileContent, content) { return fmt.Errorf("mismatched file content %v, expecting %v", fileContent, content) } @@ -211,7 +211,7 @@ func checkManyFiles(drv graphdriver.Driver, layer string, count int, seed int64) content := randomContent(64, seed+int64(i+j)) - if bytes.Compare(fileContent, content) != 0 { + if !bytes.Equal(fileContent, content) { return fmt.Errorf("mismatched file content %v, expecting %v", fileContent, content) } } @@ -300,7 +300,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { return err } - if bytes.Compare(layerIDBytes, []byte(layer)) != 0 { + if !bytes.Equal(layerIDBytes, []byte(layer)) { return fmt.Errorf("mismatched file content %v, expecting %v", layerIDBytes, []byte(layer)) } @@ -311,7 +311,7 @@ func checkManyLayers(drv graphdriver.Driver, layer string, count int) error { if err != nil { return err } - if bytes.Compare(thisLayerIDBytes, layerIDBytes) != 0 { + if !bytes.Equal(thisLayerIDBytes, layerIDBytes) { return fmt.Errorf("mismatched file content %v, expecting %v", thisLayerIDBytes, layerIDBytes) } layerIDBytes, err = ioutil.ReadFile(path.Join(layerDir, "parent-id")) diff --git a/daemon/graphdriver/lcow/lcow.go b/daemon/graphdriver/lcow/lcow.go index 86beb3d5f0..3b6e1d9ef5 100644 --- a/daemon/graphdriver/lcow/lcow.go +++ b/daemon/graphdriver/lcow/lcow.go @@ -23,33 +23,33 @@ // // * lcow.sandboxsize - Specifies a custom sandbox size in GB for starting a container // -- Possible values: >= default sandbox size (opengcs defined, currently 20) -// -- Default if ommitted: 20 +// -- Default if omitted: 20 // // The following options are read by opengcs: // // * lcow.kirdpath - Specifies a custom path to a kernel/initrd pair // -- Possible values: Any local path that is not a mapped drive -// -- Default if ommitted: %ProgramFiles%\Linux Containers +// -- Default if omitted: %ProgramFiles%\Linux Containers // // * lcow.kernel - Specifies a custom kernel file located in the `lcow.kirdpath` path // -- Possible values: Any valid filename -// -- Default if ommitted: bootx64.efi +// -- Default if omitted: bootx64.efi // // * lcow.initrd - Specifies a custom initrd file located in the `lcow.kirdpath` path // -- Possible values: Any valid filename -// -- Default if ommitted: initrd.img +// -- Default if omitted: initrd.img // // * lcow.bootparameters - Specifies additional boot parameters for booting in kernel+initrd mode // -- Possible values: Any valid linux kernel boot options -// -- Default if ommitted: +// -- Default if omitted: // // * lcow.vhdx - Specifies a custom vhdx file to boot (instead of a kernel+initrd) // -- Possible values: Any valid filename -// -- Default if ommitted: uvm.vhdx under `lcow.kirdpath` +// -- Default if omitted: uvm.vhdx under `lcow.kirdpath` // // * lcow.timeout - Specifies a timeout for utility VM operations in seconds // -- Possible values: >=0 -// -- Default if ommitted: 300 +// -- Default if omitted: 300 // TODO: Grab logs from SVM at terminate or errors @@ -836,7 +836,7 @@ func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) { ci.Unlock() // Start the SVM with a mapped virtual disk. Note that if the SVM is - // already runing and we are in global mode, this will be + // already running and we are in global mode, this will be // hot-added. mvd := &hcsshim.MappedVirtualDisk{ HostPath: ci.hostPath, diff --git a/daemon/kill.go b/daemon/kill.go index 43981513db..bb3e87cae3 100644 --- a/daemon/kill.go +++ b/daemon/kill.go @@ -160,7 +160,7 @@ func (daemon *Daemon) Kill(container *containerpkg.Container) error { // Wait for exit with no timeout. // Ignore returned status. - _ = <-container.Wait(context.Background(), containerpkg.WaitConditionNotRunning) + <-container.Wait(context.Background(), containerpkg.WaitConditionNotRunning) return nil } diff --git a/daemon/stop.go b/daemon/stop.go index c43fbfa73b..7eadba7e26 100644 --- a/daemon/stop.go +++ b/daemon/stop.go @@ -78,7 +78,7 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i // 3. If it doesn't, then send SIGKILL if err := daemon.Kill(container); err != nil { // Wait without a timeout, ignore result. - _ = <-container.Wait(context.Background(), containerpkg.WaitConditionNotRunning) + <-container.Wait(context.Background(), containerpkg.WaitConditionNotRunning) logrus.Warn(err) // Don't return error because we only care that container is stopped, not what function stopped it } } diff --git a/hack/integration-cli-on-swarm/agent/master/call.go b/hack/integration-cli-on-swarm/agent/master/call.go index 858c2c0724..dab9c67077 100644 --- a/hack/integration-cli-on-swarm/agent/master/call.go +++ b/hack/integration-cli-on-swarm/agent/master/call.go @@ -73,14 +73,14 @@ func executeTests(funkerName string, testChunks [][]string) error { } log.Printf("Finished chunk %d [%d/%d] with %d test filters in %s, code=%d.", chunkID, passed+failed, len(testChunks), len(tests), - time.Now().Sub(chunkBegin), result.Code) + time.Since(chunkBegin), result.Code) } }(chunkID, tests) } wg.Wait() // TODO: print actual tests rather than chunks log.Printf("Executed %d chunks in %s. PASS: %d, FAIL: %d.", - len(testChunks), time.Now().Sub(begin), passed, failed) + len(testChunks), time.Since(begin), passed, failed) if failed > 0 { return fmt.Errorf("%d chunks failed", failed) } @@ -103,7 +103,7 @@ func executeTestChunk(funkerName string, args types.Args) (types.Result, error) func executeTestChunkWithRetry(funkerName string, args types.Args) (types.Result, error) { begin := time.Now() - for i := 0; time.Now().Sub(begin) < funkerRetryTimeout; i++ { + for i := 0; time.Since(begin) < funkerRetryTimeout; i++ { result, err := executeTestChunk(funkerName, args) if err == nil { log.Printf("executeTestChunk(%q, %d) returned code %d in trial %d", funkerName, args.ChunkID, result.Code, i) diff --git a/hack/integration-cli-on-swarm/agent/worker/worker.go b/hack/integration-cli-on-swarm/agent/worker/worker.go index 36ab3684d2..ea8bb3fe27 100644 --- a/hack/integration-cli-on-swarm/agent/worker/worker.go +++ b/hack/integration-cli-on-swarm/agent/worker/worker.go @@ -58,7 +58,7 @@ func handle(workerImageDigest string, executor testChunkExecutor) error { RawLog: rawLog, } } - elapsed := time.Now().Sub(begin) + elapsed := time.Since(begin) log.Printf("Finished chunk %d, code=%d, elapsed=%v", args.ChunkID, code, elapsed) return types.Result{ ChunkID: args.ChunkID, diff --git a/integration-cli/docker_cli_cp_utils_test.go b/integration-cli/docker_cli_cp_utils_test.go index e517fc0f37..402a87ea90 100644 --- a/integration-cli/docker_cli_cp_utils_test.go +++ b/integration-cli/docker_cli_cp_utils_test.go @@ -193,9 +193,7 @@ func runDockerCp(c *check.C, src, dst string, params []string) (err error) { args := []string{"cp"} - for _, param := range params { - args = append(args, param) - } + args = append(args, params...) args = append(args, src, dst) diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index b36f0be14e..e179a0ebd3 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -36,7 +36,7 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) { // List of available time formats to --since unixTs := func(t time.Time) string { return fmt.Sprintf("%v", t.Unix()) } rfc3339 := func(t time.Time) string { return t.Format(time.RFC3339) } - duration := func(t time.Time) string { return time.Now().Sub(t).String() } + duration := func(t time.Time) string { return time.Since(t).String() } // --since=$start must contain only the 'untag' event for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} { diff --git a/integration-cli/fixtures/plugin/plugin.go b/integration-cli/fixtures/plugin/plugin.go index c8259be1a7..4ab15c23de 100644 --- a/integration-cli/fixtures/plugin/plugin.go +++ b/integration-cli/fixtures/plugin/plugin.go @@ -7,7 +7,7 @@ import ( "golang.org/x/net/context" ) -// CreateOpt is is passed used to change the defualt plugin config before +// CreateOpt is is passed used to change the default plugin config before // creating it type CreateOpt func(*Config) diff --git a/pkg/devicemapper/devmapper_log.go b/pkg/devicemapper/devmapper_log.go index 65a202ad2a..f2ac7da87c 100644 --- a/pkg/devicemapper/devmapper_log.go +++ b/pkg/devicemapper/devmapper_log.go @@ -12,7 +12,7 @@ import ( ) // DevmapperLogger defines methods required to register as a callback for -// logging events recieved from devicemapper. Note that devicemapper will send +// logging events received from devicemapper. Note that devicemapper will send // *all* logs regardless to callbacks (including debug logs) so it's // recommended to not spam the console with the outputs. type DevmapperLogger interface {