diff --git a/build.go b/build.go index 79569353..acb16fee 100644 --- a/build.go +++ b/build.go @@ -301,6 +301,7 @@ func runCommand(cmd string, target target) { ok = gometalinter("ineffassign", dirs) && ok ok = gometalinter("unused", dirs) && ok ok = gometalinter("staticcheck", dirs) && ok + ok = gometalinter("unconvert", dirs) && ok if !ok { os.Exit(1) } @@ -366,6 +367,7 @@ func setup() { "github.com/FiloSottile/gvt", "github.com/golang/lint/golint", "github.com/gordonklaus/ineffassign", + "github.com/mdempsky/unconvert", "github.com/mitchellh/go-wordwrap", "github.com/opennota/check/cmd/...", "github.com/tsenart/deadcode", diff --git a/cmd/stcli/utils.go b/cmd/stcli/utils.go index d6cae2b3..f9c3fbb1 100644 --- a/cmd/stcli/utils.go +++ b/cmd/stcli/utils.go @@ -140,7 +140,7 @@ func parsePort(input string) int { if port < 1 || port > 65535 { die(input + " is not a valid port\nExpected value between 1 and 65535") } - return int(port) + return port } func validAddress(input string) { diff --git a/cmd/stgenfiles/main.go b/cmd/stgenfiles/main.go index 3ce491a0..5e89150f 100644 --- a/cmd/stgenfiles/main.go +++ b/cmd/stgenfiles/main.go @@ -66,7 +66,7 @@ func generateFiles(dir string, files, maxexp int, srcname string) error { } func generateOneFile(fd io.ReadSeeker, p1 string, s int64) error { - src := io.LimitReader(&inifiteReader{fd}, int64(s)) + src := io.LimitReader(&inifiteReader{fd}, s) dst, err := os.Create(p1) if err != nil { return err diff --git a/cmd/strelaypoolsrv/main.go b/cmd/strelaypoolsrv/main.go index 16356f07..9f349822 100644 --- a/cmd/strelaypoolsrv/main.go +++ b/cmd/strelaypoolsrv/main.go @@ -249,13 +249,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") switch r.Method { case "GET": - if limit(r.RemoteAddr, getLRUCache, getMut, getLimit, int64(getLimitBurst)) { + if limit(r.RemoteAddr, getLRUCache, getMut, getLimit, getLimitBurst) { w.WriteHeader(429) return } handleGetRequest(w, r) case "POST": - if limit(r.RemoteAddr, postLRUCache, postMut, postLimit, int64(postLimitBurst)) { + if limit(r.RemoteAddr, postLRUCache, postMut, postLimit, postLimitBurst) { w.WriteHeader(429) return } diff --git a/cmd/strelaysrv/session.go b/cmd/strelaysrv/session.go index 671335ce..7a54d14d 100644 --- a/cmd/strelaysrv/session.go +++ b/cmd/strelaysrv/session.go @@ -216,7 +216,7 @@ done: func (s *session) GetClientInvitationMessage() protocol.SessionInvitation { return protocol.SessionInvitation{ From: s.serverid[:], - Key: []byte(s.clientkey), + Key: s.clientkey, Address: sessionAddress, Port: sessionPort, ServerSocket: false, @@ -226,7 +226,7 @@ func (s *session) GetClientInvitationMessage() protocol.SessionInvitation { func (s *session) GetServerInvitationMessage() protocol.SessionInvitation { return protocol.SessionInvitation{ From: s.clientid[:], - Key: []byte(s.serverkey), + Key: s.serverkey, Address: sessionAddress, Port: sessionPort, ServerSocket: true, diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index b1bf33af..12eef8d1 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -1070,7 +1070,7 @@ func getFreePort(host string, ports ...int) (int, error) { } func standbyMonitor() { - restartDelay := time.Duration(60 * time.Second) + restartDelay := 60 * time.Second now := time.Now() for { time.Sleep(10 * time.Second) diff --git a/lib/db/blockmap.go b/lib/db/blockmap.go index 57c3fb11..758c51c8 100644 --- a/lib/db/blockmap.go +++ b/lib/db/blockmap.go @@ -209,7 +209,7 @@ func blockKeyInto(o, hash []byte, folder uint32, file string) []byte { } o[0] = KeyTypeBlock binary.BigEndian.PutUint32(o[keyPrefixLen:], folder) - copy(o[keyPrefixLen+keyFolderLen:], []byte(hash)) + copy(o[keyPrefixLen+keyFolderLen:], hash) copy(o[keyPrefixLen+keyFolderLen+keyHashLen:], []byte(file)) return o } diff --git a/lib/db/leveldb_dbinstance.go b/lib/db/leveldb_dbinstance.go index dfa2630a..e16ee033 100644 --- a/lib/db/leveldb_dbinstance.go +++ b/lib/db/leveldb_dbinstance.go @@ -635,7 +635,7 @@ func (db *Instance) deviceKeyInto(k []byte, folder, device, file []byte) []byte k[0] = KeyTypeDevice binary.BigEndian.PutUint32(k[keyPrefixLen:], db.folderIdx.ID(folder)) binary.BigEndian.PutUint32(k[keyPrefixLen+keyFolderLen:], db.deviceIdx.ID(device)) - copy(k[keyPrefixLen+keyFolderLen+keyDeviceLen:], []byte(file)) + copy(k[keyPrefixLen+keyFolderLen+keyDeviceLen:], file) return k[:reqLen] } @@ -670,7 +670,7 @@ func (db *Instance) globalKey(folder, file []byte) []byte { k := make([]byte, keyPrefixLen+keyFolderLen+len(file)) k[0] = KeyTypeGlobal binary.BigEndian.PutUint32(k[keyPrefixLen:], db.folderIdx.ID(folder)) - copy(k[keyPrefixLen+keyFolderLen:], []byte(file)) + copy(k[keyPrefixLen+keyFolderLen:], file) return k } diff --git a/lib/protocol/protocol.go b/lib/protocol/protocol.go index bb5c6d84..b955e79d 100644 --- a/lib/protocol/protocol.go +++ b/lib/protocol/protocol.go @@ -522,7 +522,7 @@ func (c *rawConnection) handleRequest(req Request) { buf = make([]byte, size) } - err := c.receiver.Request(c.id, req.Folder, req.Name, int64(req.Offset), req.Hash, req.FromTemporary, buf) + err := c.receiver.Request(c.id, req.Folder, req.Name, req.Offset, req.Hash, req.FromTemporary, buf) if err != nil { c.send(&Response{ ID: req.ID, diff --git a/lib/scanner/blocks.go b/lib/scanner/blocks.go index eb5ad2bc..89a5da63 100644 --- a/lib/scanner/blocks.go +++ b/lib/scanner/blocks.go @@ -56,7 +56,7 @@ func Blocks(r io.Reader, blocksize int, sizehint int64, counter Counter) ([]prot } if counter != nil { - counter.Update(int64(n)) + counter.Update(n) } // Carve out a hash-sized chunk of "hashes" to store the hash for this @@ -72,7 +72,7 @@ func Blocks(r io.Reader, blocksize int, sizehint int64, counter Counter) ([]prot } blocks = append(blocks, b) - offset += int64(n) + offset += n hf.Reset() whf.Reset() diff --git a/lib/scanner/walk.go b/lib/scanner/walk.go index 7784a859..c296c362 100644 --- a/lib/scanner/walk.go +++ b/lib/scanner/walk.go @@ -163,7 +163,7 @@ func (w *walker) walk() (chan protocol.FileInfo, error) { for file := range toHashChan { filesToHash = append(filesToHash, file) - total += int64(file.Size) + total += file.Size } realToHashChan := make(chan protocol.FileInfo) diff --git a/lib/sync/debug.go b/lib/sync/debug.go index e0618269..ea2ffdc9 100644 --- a/lib/sync/debug.go +++ b/lib/sync/debug.go @@ -17,7 +17,7 @@ import ( ) var ( - threshold = time.Duration(100 * time.Millisecond) + threshold = 100 * time.Millisecond l = logger.DefaultLogger.NewFacility("sync", "Mutexes") // We make an exception in this package and have an actual "if debug { ...