Browse code

Add unconvert linter

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/08/25 02:11:44
Showing 23 changed files
... ...
@@ -70,7 +70,7 @@ func (s *containerRouter) getContainersStats(ctx context.Context, w http.Respons
70 70
 	config := &backend.ContainerStatsConfig{
71 71
 		Stream:    stream,
72 72
 		OutStream: w,
73
-		Version:   string(httputils.VersionFromContext(ctx)),
73
+		Version:   httputils.VersionFromContext(ctx),
74 74
 	}
75 75
 
76 76
 	return s.backend.ContainerStats(ctx, vars["name"], config)
... ...
@@ -66,9 +66,7 @@ func (s *imageRouter) postCommit(ctx context.Context, w http.ResponseWriter, r *
66 66
 		return err
67 67
 	}
68 68
 
69
-	return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{
70
-		ID: string(imgID),
71
-	})
69
+	return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{ID: imgID})
72 70
 }
73 71
 
74 72
 // Creates an image from Pull or from Import
... ...
@@ -551,7 +551,7 @@ func parseOptInterval(f *Flag) (time.Duration, error) {
551 551
 	if err != nil {
552 552
 		return 0, err
553 553
 	}
554
-	if d < time.Duration(container.MinimumDuration) {
554
+	if d < container.MinimumDuration {
555 555
 		return 0, fmt.Errorf("Interval %#v cannot be less than %s", f.name, container.MinimumDuration)
556 556
 	}
557 557
 	return d, nil
... ...
@@ -243,7 +243,7 @@ func (b *Builder) probeCache(dispatchState *dispatchState, runConfig *container.
243 243
 	}
244 244
 	fmt.Fprint(b.Stdout, " ---> Using cache\n")
245 245
 
246
-	dispatchState.imageID = string(cachedID)
246
+	dispatchState.imageID = cachedID
247 247
 	b.buildStages.update(dispatchState.imageID)
248 248
 	return true, nil
249 249
 }
... ...
@@ -3,7 +3,6 @@ package convert
3 3
 import (
4 4
 	"fmt"
5 5
 	"strings"
6
-	"time"
7 6
 
8 7
 	types "github.com/docker/docker/api/types/swarm"
9 8
 	swarmapi "github.com/docker/swarmkit/api"
... ...
@@ -115,7 +114,7 @@ func MergeSwarmSpecToGRPC(s types.Spec, spec swarmapi.ClusterSpec) (swarmapi.Clu
115 115
 		spec.Raft.ElectionTick = uint32(s.Raft.ElectionTick)
116 116
 	}
117 117
 	if s.Dispatcher.HeartbeatPeriod != 0 {
118
-		spec.Dispatcher.HeartbeatPeriod = gogotypes.DurationProto(time.Duration(s.Dispatcher.HeartbeatPeriod))
118
+		spec.Dispatcher.HeartbeatPeriod = gogotypes.DurationProto(s.Dispatcher.HeartbeatPeriod)
119 119
 	}
120 120
 	if s.CAConfig.NodeCertExpiry != 0 {
121 121
 		spec.CAConfig.NodeCertExpiry = gogotypes.DurationProto(s.CAConfig.NodeCertExpiry)
... ...
@@ -659,7 +659,7 @@ func (e *exitError) Error() string {
659 659
 }
660 660
 
661 661
 func (e *exitError) ExitCode() int {
662
-	return int(e.code)
662
+	return e.code
663 663
 }
664 664
 
665 665
 func (e *exitError) Cause() error {
... ...
@@ -158,8 +158,8 @@ func copyDir(srcDir, dstDir string, flags copyFlags) error {
158 158
 
159 159
 		// system.Chtimes doesn't support a NOFOLLOW flag atm
160 160
 		if !isSymlink {
161
-			aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
162
-			mTime := time.Unix(int64(stat.Mtim.Sec), int64(stat.Mtim.Nsec))
161
+			aTime := time.Unix(stat.Atim.Sec, stat.Atim.Nsec)
162
+			mTime := time.Unix(stat.Mtim.Sec, stat.Mtim.Nsec)
163 163
 			if err := system.Chtimes(dstPath, aTime, mTime); err != nil {
164 164
 				return err
165 165
 			}
... ...
@@ -97,10 +97,10 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
97 97
 	drivers = strings.TrimSpace(drivers)
98 98
 	v := &types.Info{
99 99
 		ID:                 daemon.ID,
100
-		Containers:         int(cRunning + cPaused + cStopped),
101
-		ContainersRunning:  int(cRunning),
102
-		ContainersPaused:   int(cPaused),
103
-		ContainersStopped:  int(cStopped),
100
+		Containers:         cRunning + cPaused + cStopped,
101
+		ContainersRunning:  cRunning,
102
+		ContainersPaused:   cPaused,
103
+		ContainersStopped:  cStopped,
104 104
 		Images:             imageCount,
105 105
 		Driver:             drivers,
106 106
 		DriverStatus:       daemon.stores[p].layerStore.DriverStatus(),
... ...
@@ -86,7 +86,7 @@ func listenFD(addr string, tlsConfig *tls.Config) ([]net.Listener, error) {
86 86
 		return nil, fmt.Errorf("failed to parse systemd fd address: should be a number: %v", addr)
87 87
 	}
88 88
 	fdOffset := fdNum - 3
89
-	if len(listeners) < int(fdOffset)+1 {
89
+	if len(listeners) < fdOffset+1 {
90 90
 		return nil, fmt.Errorf("too few socket activated files passed in by systemd")
91 91
 	}
92 92
 	if listeners[fdOffset] == nil {
... ...
@@ -834,7 +834,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
834 834
 	s.Process.NoNewPrivileges = c.NoNewPrivileges
835 835
 	s.Linux.MountLabel = c.MountLabel
836 836
 
837
-	return (*specs.Spec)(&s), nil
837
+	return &s, nil
838 838
 }
839 839
 
840 840
 func clearReadOnly(m *specs.Mount) {
... ...
@@ -84,7 +84,7 @@ func ComputeV2MetadataHMACKey(authConfig *types.AuthConfig) ([]byte, error) {
84 84
 	if err != nil {
85 85
 		return nil, err
86 86
 	}
87
-	return []byte(digest.FromBytes([]byte(buf))), nil
87
+	return []byte(digest.FromBytes(buf)), nil
88 88
 }
89 89
 
90 90
 // authConfigKeyInput is a reduced AuthConfig structure holding just relevant credential data eligible for
... ...
@@ -15,6 +15,7 @@
15 15
     "goimports",
16 16
     "golint",
17 17
     "interfacer",
18
+    "unconvert",
18 19
     "vet"
19 20
   ],
20 21
 
... ...
@@ -50,7 +50,7 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
50 50
 		return fmt.Errorf("Container %s is already active", containerID)
51 51
 	}
52 52
 
53
-	uid, gid, err := getRootIDs(specs.Spec(spec))
53
+	uid, gid, err := getRootIDs(spec)
54 54
 	if err != nil {
55 55
 		return err
56 56
 	}
... ...
@@ -180,7 +180,7 @@ func (opts *MapOpts) GetAll() map[string]string {
180 180
 }
181 181
 
182 182
 func (opts *MapOpts) String() string {
183
-	return fmt.Sprintf("%v", map[string]string((opts.values)))
183
+	return fmt.Sprintf("%v", opts.values)
184 184
 }
185 185
 
186 186
 // Type returns a string name for this Option type
... ...
@@ -18,7 +18,7 @@ func (s *QuotedString) Type() string {
18 18
 }
19 19
 
20 20
 func (s *QuotedString) String() string {
21
-	return string(*s.value)
21
+	return *s.value
22 22
 }
23 23
 
24 24
 func trimQuotes(value string) string {
... ...
@@ -50,8 +50,8 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, stat interface{}) (
50 50
 		// Currently go does not fill in the major/minors
51 51
 		if s.Mode&unix.S_IFBLK != 0 ||
52 52
 			s.Mode&unix.S_IFCHR != 0 {
53
-			hdr.Devmajor = int64(major(uint64(s.Rdev)))
54
-			hdr.Devminor = int64(minor(uint64(s.Rdev)))
53
+			hdr.Devmajor = int64(major(s.Rdev))
54
+			hdr.Devminor = int64(minor(s.Rdev))
55 55
 		}
56 56
 	}
57 57
 
... ...
@@ -62,7 +62,7 @@ func getInodeFromStat(stat interface{}) (inode uint64, err error) {
62 62
 	s, ok := stat.(*syscall.Stat_t)
63 63
 
64 64
 	if ok {
65
-		inode = uint64(s.Ino)
65
+		inode = s.Ino
66 66
 	}
67 67
 
68 68
 	return
... ...
@@ -294,7 +294,7 @@ func OverlayChanges(layers []string, rw string) ([]Change, error) {
294 294
 func overlayDeletedFile(root, path string, fi os.FileInfo) (string, error) {
295 295
 	if fi.Mode()&os.ModeCharDevice != 0 {
296 296
 		s := fi.Sys().(*syscall.Stat_t)
297
-		if major(uint64(s.Rdev)) == 0 && minor(uint64(s.Rdev)) == 0 {
297
+		if major(s.Rdev) == 0 && minor(s.Rdev) == 0 {
298 298
 			return path, nil
299 299
 		}
300 300
 	}
... ...
@@ -29,7 +29,7 @@ func (info *FileInfo) isDir() bool {
29 29
 }
30 30
 
31 31
 func getIno(fi os.FileInfo) uint64 {
32
-	return uint64(fi.Sys().(*syscall.Stat_t).Ino)
32
+	return fi.Sys().(*syscall.Stat_t).Ino
33 33
 }
34 34
 
35 35
 func hasHardlinks(fi os.FileInfo) bool {
... ...
@@ -74,7 +74,7 @@ type DefaultLogger struct {
74 74
 // DMLog is the logging callback containing all of the information from
75 75
 // devicemapper. The interface is identical to the C libdm counterpart.
76 76
 func (l DefaultLogger) DMLog(level int, file string, line, dmError int, message string) {
77
-	if int(level) <= l.Level {
77
+	if level <= l.Level {
78 78
 		// Forward the log to the correct logrus level, if allowed by dmLogLevel.
79 79
 		logMsg := fmt.Sprintf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message)
80 80
 		switch level {
... ...
@@ -34,11 +34,11 @@ func Size(dir string) (size int64, err error) {
34 34
 		// Check inode to handle hard links correctly
35 35
 		inode := fileInfo.Sys().(*syscall.Stat_t).Ino
36 36
 		// inode is not a uint64 on all platforms. Cast it to avoid issues.
37
-		if _, exists := data[uint64(inode)]; exists {
37
+		if _, exists := data[inode]; exists {
38 38
 			return nil
39 39
 		}
40 40
 		// inode is not a uint64 on all platforms. Cast it to avoid issues.
41
-		data[uint64(inode)] = struct{}{}
41
+		data[inode] = struct{}{}
42 42
 
43 43
 		size += s
44 44
 
... ...
@@ -5,10 +5,10 @@ import "syscall"
5 5
 // fromStatT converts a syscall.Stat_t type to a system.Stat_t type
6 6
 func fromStatT(s *syscall.Stat_t) (*StatT, error) {
7 7
 	return &StatT{size: s.Size,
8
-		mode: uint32(s.Mode),
8
+		mode: s.Mode,
9 9
 		uid:  s.Uid,
10 10
 		gid:  s.Gid,
11
-		rdev: uint64(s.Rdev),
11
+		rdev: s.Rdev,
12 12
 		mtim: s.Mtim}, nil
13 13
 }
14 14
 
... ...
@@ -59,7 +59,7 @@ next:
59 59
 				return nil, fmt.Errorf("Unknown character: '%s'", key)
60 60
 			}
61 61
 		} else {
62
-			codes = append(codes, byte(key[0]))
62
+			codes = append(codes, key[0])
63 63
 		}
64 64
 	}
65 65
 	return codes, nil
... ...
@@ -18,7 +18,6 @@ import (
18 18
 	"github.com/docker/docker/pkg/stringid"
19 19
 	"github.com/docker/docker/plugin/v2"
20 20
 	"github.com/opencontainers/go-digest"
21
-	specs "github.com/opencontainers/runtime-spec/specs-go"
22 21
 	"github.com/pkg/errors"
23 22
 	"github.com/sirupsen/logrus"
24 23
 	"golang.org/x/sys/unix"
... ...
@@ -62,7 +61,7 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error {
62 62
 		return errors.WithStack(err)
63 63
 	}
64 64
 
65
-	if err := pm.containerdClient.Create(p.GetID(), "", "", specs.Spec(*spec), attachToLog(p.GetID())); err != nil {
65
+	if err := pm.containerdClient.Create(p.GetID(), "", "", *spec, attachToLog(p.GetID())); err != nil {
66 66
 		if p.PropagatedMount != "" {
67 67
 			if err := mount.Unmount(p.PropagatedMount); err != nil {
68 68
 				logrus.Warnf("Could not unmount %s: %v", p.PropagatedMount, err)