Skip to content

Commit

Permalink
Fix golint errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <[email protected]>
  • Loading branch information
dnephin committed Aug 18, 2017
1 parent d7e2c4c commit 9b47b7b
Show file tree
Hide file tree
Showing 29 changed files with 51 additions and 47 deletions.
1 change: 1 addition & 0 deletions api/server/middleware/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
w.Header().Set("Server", header)
w.Header().Set("API-Version", v.defaultVersion)
w.Header().Set("OSType", runtime.GOOS)
// nolint: golint
ctx = context.WithValue(ctx, "api-version", apiVersion)
return handler(ctx, w, r, vars)
}
Expand Down
2 changes: 1 addition & 1 deletion builder/dockerfile/parser/line_parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

var (
errDockerfileNotStringArray = errors.New("When using JSON array syntax, arrays must be comprised of strings only.")
errDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only")
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
c, err := config.MergeDaemonConfigurations(conf, flags, opts.configFile)
if err != nil {
if flags.Changed("config-file") || !os.IsNotExist(err) {
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v\n", opts.configFile, err)
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v", opts.configFile, err)
}
}
// the merged configuration can be nil if the config file didn't exist.
Expand Down
4 changes: 2 additions & 2 deletions daemon/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA
return err
}
if container.IsPaused() {
err := fmt.Errorf("Container %s is paused, unpause the container before attach.", prefixOrName)
err := fmt.Errorf("container %s is paused, unpause the container before attach", prefixOrName)
return stateConflictError{err}
}
if container.IsRestarting() {
err := fmt.Errorf("Container %s is restarting, wait until the container is running.", prefixOrName)
err := fmt.Errorf("container %s is restarting, wait until the container is running", prefixOrName)
return stateConflictError{err}
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var (
// containerd if none is specified
DefaultRuntimeBinary = "docker-runc"

errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform")
)

type daemonStore struct {
Expand Down
8 changes: 4 additions & 4 deletions daemon/daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,13 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
// check for various conflicting options with user namespaces
if daemon.configStore.RemappedRoot != "" && hostConfig.UsernsMode.IsPrivate() {
if hostConfig.Privileged {
return warnings, fmt.Errorf("Privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode.")
return warnings, fmt.Errorf("privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode")
}
if hostConfig.NetworkMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
return warnings, fmt.Errorf("Cannot share the host's network namespace when user namespaces are enabled")
return warnings, fmt.Errorf("cannot share the host's network namespace when user namespaces are enabled")
}
if hostConfig.PidMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
return warnings, fmt.Errorf("Cannot share the host PID namespace when user namespaces are enabled")
return warnings, fmt.Errorf("cannot share the host PID namespace when user namespaces are enabled")
}
}
if hostConfig.CgroupParent != "" && UsingSystemd(daemon.configStore) {
Expand Down Expand Up @@ -1125,7 +1125,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, rootIDs idtools.IDPa
break
}
if !idtools.CanAccess(dirPath, rootIDs) {
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)
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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/graphdriver/devmapper/deviceset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
devices.metaDataLoopbackSize = size
case "dm.fs":
if val != "ext4" && val != "xfs" {
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s\n", val)
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s", val)
}
devices.filesystem = val
case "dm.mkfsarg":
Expand Down Expand Up @@ -2786,7 +2786,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
Level: int(level),
})
default:
return nil, fmt.Errorf("devmapper: Unknown option %s\n", key)
return nil, fmt.Errorf("devmapper: Unknown option %s", key)
}
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/graphdriver/overlay/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func copyDir(srcDir, dstDir string, flags copyFlags) error {
}

default:
return fmt.Errorf("Unknown file type for %s\n", srcPath)
return fmt.Errorf("unknown file type for %s", srcPath)
}

// Everything below is copying metadata from src to dst. All this metadata
Expand Down
2 changes: 1 addition & 1 deletion daemon/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container
return nil, err
}
if info.ExitCode == nil {
return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", cntr.ID)
return nil, fmt.Errorf("healthcheck for container %s has no exit code", cntr.ID)
}
// Note: Go's json package will handle invalid UTF-8 for us
out := output.String()
Expand Down
4 changes: 2 additions & 2 deletions daemon/logger/awslogs/cloudwatchlogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestCreateError(t *testing.T) {
client: mockClient,
}
mockClient.createLogStreamResult <- &createLogStreamResult{
errorResult: errors.New("Error!"),
errorResult: errors.New("Error"),
}

err := stream.create()
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestPublishBatchError(t *testing.T) {
sequenceToken: aws.String(sequenceToken),
}
mockClient.putLogEventsResult <- &putLogEventsResult{
errorResult: errors.New("Error!"),
errorResult: errors.New("Error"),
}

events := []wrappedEvent{
Expand Down
2 changes: 1 addition & 1 deletion daemon/logger/splunk/splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func New(info logger.Info) (logger.Logger, error) {
}
gzipCompressionLevel = int(gzipCompressionLevel64)
if gzipCompressionLevel < gzip.DefaultCompression || gzipCompressionLevel > gzip.BestCompression {
err := fmt.Errorf("Not supported level '%s' for %s (supported values between %d and %d).",
err := fmt.Errorf("not supported level '%s' for %s (supported values between %d and %d)",
gzipCompressionLevelStr, splunkGzipCompressionLevelKey, gzip.DefaultCompression, gzip.BestCompression)
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
case libcontainerd.StateOOM:
// StateOOM is Linux specific and should never be hit on Windows
if runtime.GOOS == "windows" {
return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.")
return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
}
daemon.updateHealthMonitor(c)
if err := c.CheckpointTo(daemon.containersReplica); err != nil {
Expand Down
1 change: 1 addition & 0 deletions daemon/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
if err != nil {
if _, ok := err.(libnetwork.ErrDataStoreNotInitialized); ok {
// nolint: golint
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.")
}
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions daemon/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func ensureShared(path string) error {
}

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

if !sharedMount && !slaveMount {
return fmt.Errorf("Path %s is mounted on %s but it is not a shared or slave mount.", path, sourceMount)
return fmt.Errorf("path %s is mounted on %s but it is not a shared or slave mount", path, sourceMount)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
defer container.Unlock()

if container.Paused {
return stateConflictError{errors.New("Cannot start a paused container, try unpause instead.")}
return stateConflictError{errors.New("cannot start a paused container, try unpause instead")}
}

if container.Running {
return containerNotModifiedError{running: true}
}

if container.RemovalInProgress || container.Dead {
return stateConflictError{errors.New("Container is marked for removal and cannot be started.")}
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
}
return nil
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
}

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

// if we encounter an error during start we need to ensure that any other
Expand Down
2 changes: 1 addition & 1 deletion daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
}()

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

container.Lock()
Expand Down
2 changes: 1 addition & 1 deletion distribution/pull_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func fixManifestLayers(m *schema1.Manifest) error {
m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...)
m.History = append(m.History[:i], m.History[i+1:]...)
} else if imgs[i].Parent != imgs[i+1].ID {
return fmt.Errorf("Invalid parent ID. Expected %v, got %v.", imgs[i+1].ID, imgs[i].Parent)
return fmt.Errorf("invalid parent ID. Expected %v, got %v", imgs[i+1].ID, imgs[i].Parent)
}
}

Expand Down
6 changes: 3 additions & 3 deletions distribution/pull_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/testutil"
"github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -102,9 +103,8 @@ func TestFixManifestLayersBadParent(t *testing.T) {
},
}

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

// TestValidateManifest verifies the validateManifest function
Expand Down
7 changes: 6 additions & 1 deletion hack/validate/gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"Vendor": true,
"Deadline": "2m",
"Sort": ["linter", "severity", "path"],
"Exclude": [".*\\.pb\\.go"],
"Exclude": [
".*\\.pb\\.go",
"dockerversion/version_autogen.go",
"api/types/container/container_.*",
"integration-cli/"
],

"Enable": [
"gofmt",
Expand Down
2 changes: 1 addition & 1 deletion integration-cli/docker_cli_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
// an error should have been shown that you cannot start paused container
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
// an error should have been shown that you cannot start paused container
c.Assert(out, checker.Contains, "Cannot start a paused container, try unpause instead.")
c.Assert(out, checker.Contains, "cannot start a paused container, try unpause instead")
}

func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
return nil

default:
return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag)
}

// Lchown is not supported on Windows.
Expand Down
7 changes: 3 additions & 4 deletions pkg/ioutils/readers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

// Implement io.Reader
type errorReader struct{}

func (r *errorReader) Read(p []byte) (int, error) {
return 0, fmt.Errorf("Error reader always fail.")
return 0, fmt.Errorf("error reader always fail")
}

func TestReadCloserWrapperClose(t *testing.T) {
Expand All @@ -35,9 +36,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) {
called = true
})
_, err := wrapper.Read([]byte{})
if err == nil || !strings.Contains(err.Error(), "Error reader always fail.") {
t.Fatalf("readErrWrapper should returned an error")
}
assert.EqualError(t, err, "error reader always fail")
if !called {
t.Fatalf("readErrWrapper should have call the anonymous function on failure")
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/jsonmessage/jsonmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (
"strings"
"time"

"github.com/Nvveen/Gotty"

gotty "github.com/Nvveen/Gotty"
"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/term"
"github.com/docker/go-units"
units "github.com/docker/go-units"
)

// JSONError wraps a concrete Code and Message, `Code` is
Expand Down Expand Up @@ -187,7 +186,7 @@ func cursorDown(out io.Writer, ti termInfo, l int) {
func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error {
if jm.Error != nil {
if jm.Error.Code == 401 {
return fmt.Errorf("Authentication is required.")
return fmt.Errorf("authentication is required")
}
return jm.Error
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/jsonmessage/jsonmessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/term"
"github.com/stretchr/testify/assert"
)

func TestError(t *testing.T) {
Expand Down Expand Up @@ -198,9 +199,7 @@ func TestJSONMessageDisplayWithJSONError(t *testing.T) {

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

func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/testutil/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *Result) Assert(t testingT, exp Expected) *Result {
}
_, file, line, ok := runtime.Caller(1)
if ok {
t.Fatalf("at %s:%d - %s", filepath.Base(file), line, err.Error())
t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error())
} else {
t.Fatalf("(no file/line info) - %s", err.Error())
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *Result) Compare(exp Expected) error {
if len(errors) == 0 {
return nil
}
return fmt.Errorf("%s\nFailures:\n%s\n", r, strings.Join(errors, "\n"))
return fmt.Errorf("%s\nFailures:\n%s", r, strings.Join(errors, "\n"))
}

func matchOutput(expected string, actual string) bool {
Expand Down
2 changes: 1 addition & 1 deletion registry/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func loginV1(authConfig *types.AuthConfig, apiEndpoint APIEndpoint, userAgent st
logrus.Debugf("attempting v1 login to registry endpoint %s", serverAddress)

if serverAddress == "" {
return "", "", systemError{errors.New("Server Error: Server Address not set.")}
return "", "", systemError{errors.New("server Error: Server Address not set")}
}

req, err := http.NewRequest("GET", serverAddress+"users/", nil)
Expand Down
2 changes: 1 addition & 1 deletion registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func ValidateIndexName(val string) (string, error) {
val = "docker.io"
}
if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") {
return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val)
return "", fmt.Errorf("invalid index name (%s). Cannot begin or end with a hyphen", val)
}
return val, nil
}
Expand Down
2 changes: 1 addition & 1 deletion registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
keyName := certName[:len(certName)-5] + ".key"
logrus.Debugf("cert: %s", filepath.Join(directory, f.Name()))
if !hasFile(fs, keyName) {
return fmt.Errorf("Missing key %s for client certificate %s. Note that CA certificates should use the extension .crt.", keyName, certName)
return fmt.Errorf("missing key %s for client certificate %s. Note that CA certificates should use the extension .crt", keyName, certName)
}
cert, err := tls.LoadX509KeyPair(filepath.Join(directory, certName), filepath.Join(directory, keyName))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion registry/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro
// "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout"
// was a top search on the docker user forum
if isTimeout(err) {
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)
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)
}
return nil, fmt.Errorf("Error while pulling image: %v", err)
}
Expand Down

0 comments on commit 9b47b7b

Please sign in to comment.