staticcheck guided refactoring
This commit is contained in:
parent
9bc5323e66
commit
376dba5810
4
Makefile
4
Makefile
@ -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 ./...
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)")
|
||||
|
Loading…
Reference in New Issue
Block a user