Skip to content

Commit 9b47b7b

Browse files
committed
Fix golint errors.
Signed-off-by: Daniel Nephin <[email protected]>
1 parent d7e2c4c commit 9b47b7b

File tree

29 files changed

+51
-47
lines changed

29 files changed

+51
-47
lines changed

api/server/middleware/version.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
5353
w.Header().Set("Server", header)
5454
w.Header().Set("API-Version", v.defaultVersion)
5555
w.Header().Set("OSType", runtime.GOOS)
56+
// nolint: golint
5657
ctx = context.WithValue(ctx, "api-version", apiVersion)
5758
return handler(ctx, w, r, vars)
5859
}

builder/dockerfile/parser/line_parsers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
var (
22-
errDockerfileNotStringArray = errors.New("When using JSON array syntax, arrays must be comprised of strings only.")
22+
errDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only")
2323
)
2424

2525
const (

cmd/dockerd/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
453453
c, err := config.MergeDaemonConfigurations(conf, flags, opts.configFile)
454454
if err != nil {
455455
if flags.Changed("config-file") || !os.IsNotExist(err) {
456-
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v\n", opts.configFile, err)
456+
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v", opts.configFile, err)
457457
}
458458
}
459459
// the merged configuration can be nil if the config file didn't exist.

daemon/attach.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA
3131
return err
3232
}
3333
if container.IsPaused() {
34-
err := fmt.Errorf("Container %s is paused, unpause the container before attach.", prefixOrName)
34+
err := fmt.Errorf("container %s is paused, unpause the container before attach", prefixOrName)
3535
return stateConflictError{err}
3636
}
3737
if container.IsRestarting() {
38-
err := fmt.Errorf("Container %s is restarting, wait until the container is running.", prefixOrName)
38+
err := fmt.Errorf("container %s is restarting, wait until the container is running", prefixOrName)
3939
return stateConflictError{err}
4040
}
4141

daemon/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666
// containerd if none is specified
6767
DefaultRuntimeBinary = "docker-runc"
6868

69-
errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
69+
errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform")
7070
)
7171

7272
type daemonStore struct {

daemon/daemon_unix.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,13 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
557557
// check for various conflicting options with user namespaces
558558
if daemon.configStore.RemappedRoot != "" && hostConfig.UsernsMode.IsPrivate() {
559559
if hostConfig.Privileged {
560-
return warnings, fmt.Errorf("Privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode.")
560+
return warnings, fmt.Errorf("privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode")
561561
}
562562
if hostConfig.NetworkMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
563-
return warnings, fmt.Errorf("Cannot share the host's network namespace when user namespaces are enabled")
563+
return warnings, fmt.Errorf("cannot share the host's network namespace when user namespaces are enabled")
564564
}
565565
if hostConfig.PidMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
566-
return warnings, fmt.Errorf("Cannot share the host PID namespace when user namespaces are enabled")
566+
return warnings, fmt.Errorf("cannot share the host PID namespace when user namespaces are enabled")
567567
}
568568
}
569569
if hostConfig.CgroupParent != "" && UsingSystemd(daemon.configStore) {
@@ -1125,7 +1125,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, rootIDs idtools.IDPa
11251125
break
11261126
}
11271127
if !idtools.CanAccess(dirPath, rootIDs) {
1128-
return fmt.Errorf("A subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories.", config.Root)
1128+
return fmt.Errorf("a subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories", config.Root)
11291129
}
11301130
}
11311131
}

daemon/graphdriver/devmapper/deviceset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
26642664
devices.metaDataLoopbackSize = size
26652665
case "dm.fs":
26662666
if val != "ext4" && val != "xfs" {
2667-
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s\n", val)
2667+
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s", val)
26682668
}
26692669
devices.filesystem = val
26702670
case "dm.mkfsarg":
@@ -2786,7 +2786,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
27862786
Level: int(level),
27872787
})
27882788
default:
2789-
return nil, fmt.Errorf("devmapper: Unknown option %s\n", key)
2789+
return nil, fmt.Errorf("devmapper: Unknown option %s", key)
27902790
}
27912791
}
27922792

daemon/graphdriver/overlay/copy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func copyDir(srcDir, dstDir string, flags copyFlags) error {
121121
}
122122

123123
default:
124-
return fmt.Errorf("Unknown file type for %s\n", srcPath)
124+
return fmt.Errorf("unknown file type for %s", srcPath)
125125
}
126126

127127
// Everything below is copying metadata from src to dst. All this metadata

daemon/health.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container
101101
return nil, err
102102
}
103103
if info.ExitCode == nil {
104-
return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", cntr.ID)
104+
return nil, fmt.Errorf("healthcheck for container %s has no exit code", cntr.ID)
105105
}
106106
// Note: Go's json package will handle invalid UTF-8 for us
107107
out := output.String()

daemon/logger/awslogs/cloudwatchlogs_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestCreateError(t *testing.T) {
162162
client: mockClient,
163163
}
164164
mockClient.createLogStreamResult <- &createLogStreamResult{
165-
errorResult: errors.New("Error!"),
165+
errorResult: errors.New("Error"),
166166
}
167167

168168
err := stream.create()
@@ -243,7 +243,7 @@ func TestPublishBatchError(t *testing.T) {
243243
sequenceToken: aws.String(sequenceToken),
244244
}
245245
mockClient.putLogEventsResult <- &putLogEventsResult{
246-
errorResult: errors.New("Error!"),
246+
errorResult: errors.New("Error"),
247247
}
248248

249249
events := []wrappedEvent{

daemon/logger/splunk/splunk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func New(info logger.Info) (logger.Logger, error) {
203203
}
204204
gzipCompressionLevel = int(gzipCompressionLevel64)
205205
if gzipCompressionLevel < gzip.DefaultCompression || gzipCompressionLevel > gzip.BestCompression {
206-
err := fmt.Errorf("Not supported level '%s' for %s (supported values between %d and %d).",
206+
err := fmt.Errorf("not supported level '%s' for %s (supported values between %d and %d)",
207207
gzipCompressionLevelStr, splunkGzipCompressionLevelKey, gzip.DefaultCompression, gzip.BestCompression)
208208
return nil, err
209209
}

daemon/monitor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
3636
case libcontainerd.StateOOM:
3737
// StateOOM is Linux specific and should never be hit on Windows
3838
if runtime.GOOS == "windows" {
39-
return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.")
39+
return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
4040
}
4141
daemon.updateHealthMonitor(c)
4242
if err := c.CheckpointTo(daemon.containersReplica); err != nil {

daemon/network.go

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
348348
n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
349349
if err != nil {
350350
if _, ok := err.(libnetwork.ErrDataStoreNotInitialized); ok {
351+
// nolint: golint
351352
return nil, errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.")
352353
}
353354
return nil, err

daemon/oci_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func ensureShared(path string) error {
438438
}
439439

440440
if !sharedMount {
441-
return fmt.Errorf("Path %s is mounted on %s but it is not a shared mount.", path, sourceMount)
441+
return fmt.Errorf("path %s is mounted on %s but it is not a shared mount", path, sourceMount)
442442
}
443443
return nil
444444
}
@@ -465,7 +465,7 @@ func ensureSharedOrSlave(path string) error {
465465
}
466466

467467
if !sharedMount && !slaveMount {
468-
return fmt.Errorf("Path %s is mounted on %s but it is not a shared or slave mount.", path, sourceMount)
468+
return fmt.Errorf("path %s is mounted on %s but it is not a shared or slave mount", path, sourceMount)
469469
}
470470
return nil
471471
}

daemon/start.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
2727
defer container.Unlock()
2828

2929
if container.Paused {
30-
return stateConflictError{errors.New("Cannot start a paused container, try unpause instead.")}
30+
return stateConflictError{errors.New("cannot start a paused container, try unpause instead")}
3131
}
3232

3333
if container.Running {
3434
return containerNotModifiedError{running: true}
3535
}
3636

3737
if container.RemovalInProgress || container.Dead {
38-
return stateConflictError{errors.New("Container is marked for removal and cannot be started.")}
38+
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
3939
}
4040
return nil
4141
}
@@ -110,7 +110,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
110110
}
111111

112112
if container.RemovalInProgress || container.Dead {
113-
return stateConflictError{errors.New("Container is marked for removal and cannot be started.")}
113+
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
114114
}
115115

116116
// if we encounter an error during start we need to ensure that any other

daemon/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
5050
}()
5151

5252
if container.RemovalInProgress || container.Dead {
53-
return errCannotUpdate(container.ID, fmt.Errorf("Container is marked for removal and cannot be \"update\"."))
53+
return errCannotUpdate(container.ID, fmt.Errorf("container is marked for removal and cannot be \"update\""))
5454
}
5555

5656
container.Lock()

distribution/pull_v2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ func fixManifestLayers(m *schema1.Manifest) error {
908908
m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...)
909909
m.History = append(m.History[:i], m.History[i+1:]...)
910910
} else if imgs[i].Parent != imgs[i+1].ID {
911-
return fmt.Errorf("Invalid parent ID. Expected %v, got %v.", imgs[i+1].ID, imgs[i].Parent)
911+
return fmt.Errorf("invalid parent ID. Expected %v, got %v", imgs[i+1].ID, imgs[i].Parent)
912912
}
913913
}
914914

distribution/pull_v2_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/docker/distribution/manifest/schema1"
1212
"github.com/docker/distribution/reference"
13+
"github.com/docker/docker/pkg/testutil"
1314
"github.com/opencontainers/go-digest"
1415
)
1516

@@ -102,9 +103,8 @@ func TestFixManifestLayersBadParent(t *testing.T) {
102103
},
103104
}
104105

105-
if err := fixManifestLayers(&duplicateLayerManifest); err == nil || !strings.Contains(err.Error(), "Invalid parent ID.") {
106-
t.Fatalf("expected an invalid parent ID error from fixManifestLayers")
107-
}
106+
err := fixManifestLayers(&duplicateLayerManifest)
107+
testutil.ErrorContains(t, err, "invalid parent ID")
108108
}
109109

110110
// TestValidateManifest verifies the validateManifest function

hack/validate/gometalinter.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"Vendor": true,
33
"Deadline": "2m",
44
"Sort": ["linter", "severity", "path"],
5-
"Exclude": [".*\\.pb\\.go"],
5+
"Exclude": [
6+
".*\\.pb\\.go",
7+
"dockerversion/version_autogen.go",
8+
"api/types/container/container_.*",
9+
"integration-cli/"
10+
],
611

712
"Enable": [
813
"gofmt",

integration-cli/docker_cli_start_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
103103
// an error should have been shown that you cannot start paused container
104104
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
105105
// an error should have been shown that you cannot start paused container
106-
c.Assert(out, checker.Contains, "Cannot start a paused container, try unpause instead.")
106+
c.Assert(out, checker.Contains, "cannot start a paused container, try unpause instead")
107107
}
108108

109109
func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {

pkg/archive/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
595595
return nil
596596

597597
default:
598-
return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
598+
return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag)
599599
}
600600

601601
// Lchown is not supported on Windows.

pkg/ioutils/readers_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/stretchr/testify/assert"
1011
"golang.org/x/net/context"
1112
)
1213

1314
// Implement io.Reader
1415
type errorReader struct{}
1516

1617
func (r *errorReader) Read(p []byte) (int, error) {
17-
return 0, fmt.Errorf("Error reader always fail.")
18+
return 0, fmt.Errorf("error reader always fail")
1819
}
1920

2021
func TestReadCloserWrapperClose(t *testing.T) {
@@ -35,9 +36,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) {
3536
called = true
3637
})
3738
_, err := wrapper.Read([]byte{})
38-
if err == nil || !strings.Contains(err.Error(), "Error reader always fail.") {
39-
t.Fatalf("readErrWrapper should returned an error")
40-
}
39+
assert.EqualError(t, err, "error reader always fail")
4140
if !called {
4241
t.Fatalf("readErrWrapper should have call the anonymous function on failure")
4342
}

pkg/jsonmessage/jsonmessage.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/Nvveen/Gotty"
12-
11+
gotty "github.com/Nvveen/Gotty"
1312
"github.com/docker/docker/pkg/jsonlog"
1413
"github.com/docker/docker/pkg/term"
15-
"github.com/docker/go-units"
14+
units "github.com/docker/go-units"
1615
)
1716

1817
// JSONError wraps a concrete Code and Message, `Code` is
@@ -187,7 +186,7 @@ func cursorDown(out io.Writer, ti termInfo, l int) {
187186
func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error {
188187
if jm.Error != nil {
189188
if jm.Error.Code == 401 {
190-
return fmt.Errorf("Authentication is required.")
189+
return fmt.Errorf("authentication is required")
191190
}
192191
return jm.Error
193192
}

pkg/jsonmessage/jsonmessage_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/docker/docker/pkg/jsonlog"
1212
"github.com/docker/docker/pkg/term"
13+
"github.com/stretchr/testify/assert"
1314
)
1415

1516
func TestError(t *testing.T) {
@@ -198,9 +199,7 @@ func TestJSONMessageDisplayWithJSONError(t *testing.T) {
198199

199200
jsonMessage = JSONMessage{Error: &JSONError{401, "Anything"}}
200201
err = jsonMessage.Display(data, &noTermInfo{})
201-
if err == nil || err.Error() != "Authentication is required." {
202-
t.Fatalf("Expected an error \"Authentication is required.\", got %q", err)
203-
}
202+
assert.EqualError(t, err, "authentication is required")
204203
}
205204

206205
func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) {

pkg/testutil/cmd/command.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r *Result) Assert(t testingT, exp Expected) *Result {
6161
}
6262
_, file, line, ok := runtime.Caller(1)
6363
if ok {
64-
t.Fatalf("at %s:%d - %s", filepath.Base(file), line, err.Error())
64+
t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error())
6565
} else {
6666
t.Fatalf("(no file/line info) - %s", err.Error())
6767
}
@@ -108,7 +108,7 @@ func (r *Result) Compare(exp Expected) error {
108108
if len(errors) == 0 {
109109
return nil
110110
}
111-
return fmt.Errorf("%s\nFailures:\n%s\n", r, strings.Join(errors, "\n"))
111+
return fmt.Errorf("%s\nFailures:\n%s", r, strings.Join(errors, "\n"))
112112
}
113113

114114
func matchOutput(expected string, actual string) bool {

registry/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func loginV1(authConfig *types.AuthConfig, apiEndpoint APIEndpoint, userAgent st
2929
logrus.Debugf("attempting v1 login to registry endpoint %s", serverAddress)
3030

3131
if serverAddress == "" {
32-
return "", "", systemError{errors.New("Server Error: Server Address not set.")}
32+
return "", "", systemError{errors.New("server Error: Server Address not set")}
3333
}
3434

3535
req, err := http.NewRequest("GET", serverAddress+"users/", nil)

registry/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func ValidateIndexName(val string) (string, error) {
354354
val = "docker.io"
355355
}
356356
if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") {
357-
return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val)
357+
return "", fmt.Errorf("invalid index name (%s). Cannot begin or end with a hyphen", val)
358358
}
359359
return val, nil
360360
}

registry/registry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
8181
keyName := certName[:len(certName)-5] + ".key"
8282
logrus.Debugf("cert: %s", filepath.Join(directory, f.Name()))
8383
if !hasFile(fs, keyName) {
84-
return fmt.Errorf("Missing key %s for client certificate %s. Note that CA certificates should use the extension .crt.", keyName, certName)
84+
return fmt.Errorf("missing key %s for client certificate %s. Note that CA certificates should use the extension .crt", keyName, certName)
8585
}
8686
cert, err := tls.LoadX509KeyPair(filepath.Join(directory, certName), filepath.Join(directory, keyName))
8787
if err != nil {

registry/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro
434434
// "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout"
435435
// was a top search on the docker user forum
436436
if isTimeout(err) {
437-
return nil, fmt.Errorf("Network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy.", repositoryTarget)
437+
return nil, fmt.Errorf("network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy", repositoryTarget)
438438
}
439439
return nil, fmt.Errorf("Error while pulling image: %v", err)
440440
}

0 commit comments

Comments
 (0)