staticcheck guided refactoring

This commit is contained in:
Bora M. Alper 2020-11-27 18:06:43 +00:00
parent 9bc5323e66
commit 376dba5810
No known key found for this signature in database
GPG Key ID: 8F1A9504E1BD114D
6 changed files with 11 additions and 9 deletions

View File

@ -9,6 +9,8 @@ magneticow:
# TODO: minify files!
# https://github.com/kevinburke/go-bindata
go-bindata -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" cmd/magneticow/data/...
# Prepend the linter instruction to the beginning of the file
sed -i '1s;^;//lint:file-ignore * Ignore file altogether\n;' cmd/magneticow/bindata.go
go install --tags fts5 "-ldflags=-s -w -X main.compiledOn=`date -u +%Y-%m-%dT%H:%M:%SZ`" ./cmd/magneticow
.PHONY: docker
@ -38,7 +40,7 @@ vet:
go vet ./...
staticcheck:
./misc/staticcheck/staticcheck ./...
./misc/staticcheck/staticcheck -fail all ./...
test:
go test ./...

View File

@ -471,7 +471,7 @@ func toBigEndian(i uint, n int) []byte {
binary.BigEndian.PutUint32(b, uint32(i))
default:
panic(fmt.Sprintf("n must be 1, 2, or 4!"))
panic("n must be 1, 2, or 4!")
}
if len(b) != n {

View File

@ -273,7 +273,7 @@ func (e *Error) UnmarshalBencode(b []byte) (err error) {
}
if len(matches[2]) != msgLen {
return fmt.Errorf("error message have different lengths (%d vs %d) \"%s\"!", len(matches[2]), msgLen, matches[2])
return fmt.Errorf("error message have different lengths (%d vs %d) \"%s\"", len(matches[2]), msgLen, matches[2])
}
e.Code = code

View File

@ -327,6 +327,7 @@ func validatePingORannouncePeerResponseMessage(msg *Message) bool {
}
func validateFindNodeResponseMessage(msg *Message) bool {
//lint:ignore S1008 to be done later
if len(msg.R.ID) != 20 {
return false
}

View File

@ -39,7 +39,6 @@ func torrentsInfohashHandler(w http.ResponseWriter, r *http.Request) {
// Cache static resources for a day
w.Header().Set("Cache-Control", "max-age=86400")
_, _ = w.Write(data)
return
}
func statisticsHandler(w http.ResponseWriter, r *http.Request) {

View File

@ -218,8 +218,8 @@ func (db *sqlite3Database) GetNumberOfTorrents() (uint, error) {
}
defer rows.Close()
if rows.Next() != true {
return 0, fmt.Errorf("No rows returned from `SELECT MAX(ROWID)`")
if !rows.Next() {
return 0, fmt.Errorf("no rows returned from `SELECT MAX(ROWID)`")
}
var n *uint
@ -384,7 +384,7 @@ func (db *sqlite3Database) GetTorrent(infoHash []byte) (*TorrentMetadata, error)
return nil, err
}
if rows.Next() != true {
if !rows.Next() {
return nil, nil
}
@ -547,8 +547,8 @@ func (db *sqlite3Database) setupDatabase() error {
}
defer rows.Close()
var userVersion int
if rows.Next() != true {
return fmt.Errorf("sql.Rows.Next (user_version): PRAGMA user_version did not return any rows!")
if !rows.Next() {
return fmt.Errorf("sql.Rows.Next (user_version): PRAGMA user_version did not return any rows")
}
if err = rows.Scan(&userVersion); err != nil {
return errors.Wrap(err, "sql.Rows.Scan (user_version)")