staticcheck guided refactoring
This commit is contained in:
parent
9bc5323e66
commit
376dba5810
4
Makefile
4
Makefile
@ -9,6 +9,8 @@ magneticow:
|
|||||||
# TODO: minify files!
|
# TODO: minify files!
|
||||||
# https://github.com/kevinburke/go-bindata
|
# https://github.com/kevinburke/go-bindata
|
||||||
go-bindata -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" cmd/magneticow/data/...
|
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
|
go install --tags fts5 "-ldflags=-s -w -X main.compiledOn=`date -u +%Y-%m-%dT%H:%M:%SZ`" ./cmd/magneticow
|
||||||
|
|
||||||
.PHONY: docker
|
.PHONY: docker
|
||||||
@ -38,7 +40,7 @@ vet:
|
|||||||
go vet ./...
|
go vet ./...
|
||||||
|
|
||||||
staticcheck:
|
staticcheck:
|
||||||
./misc/staticcheck/staticcheck ./...
|
./misc/staticcheck/staticcheck -fail all ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test ./...
|
go test ./...
|
||||||
|
@ -471,7 +471,7 @@ func toBigEndian(i uint, n int) []byte {
|
|||||||
binary.BigEndian.PutUint32(b, uint32(i))
|
binary.BigEndian.PutUint32(b, uint32(i))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("n must be 1, 2, or 4!"))
|
panic("n must be 1, 2, or 4!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(b) != n {
|
if len(b) != n {
|
||||||
|
@ -273,7 +273,7 @@ func (e *Error) UnmarshalBencode(b []byte) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(matches[2]) != msgLen {
|
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
|
e.Code = code
|
||||||
|
@ -327,6 +327,7 @@ func validatePingORannouncePeerResponseMessage(msg *Message) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateFindNodeResponseMessage(msg *Message) bool {
|
func validateFindNodeResponseMessage(msg *Message) bool {
|
||||||
|
//lint:ignore S1008 to be done later
|
||||||
if len(msg.R.ID) != 20 {
|
if len(msg.R.ID) != 20 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ func torrentsInfohashHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Cache static resources for a day
|
// Cache static resources for a day
|
||||||
w.Header().Set("Cache-Control", "max-age=86400")
|
w.Header().Set("Cache-Control", "max-age=86400")
|
||||||
_, _ = w.Write(data)
|
_, _ = w.Write(data)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func statisticsHandler(w http.ResponseWriter, r *http.Request) {
|
func statisticsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -218,8 +218,8 @@ func (db *sqlite3Database) GetNumberOfTorrents() (uint, error) {
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
if rows.Next() != true {
|
if !rows.Next() {
|
||||||
return 0, fmt.Errorf("No rows returned from `SELECT MAX(ROWID)`")
|
return 0, fmt.Errorf("no rows returned from `SELECT MAX(ROWID)`")
|
||||||
}
|
}
|
||||||
|
|
||||||
var n *uint
|
var n *uint
|
||||||
@ -384,7 +384,7 @@ func (db *sqlite3Database) GetTorrent(infoHash []byte) (*TorrentMetadata, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows.Next() != true {
|
if !rows.Next() {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,8 +547,8 @@ func (db *sqlite3Database) setupDatabase() error {
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var userVersion int
|
var userVersion int
|
||||||
if rows.Next() != true {
|
if !rows.Next() {
|
||||||
return fmt.Errorf("sql.Rows.Next (user_version): PRAGMA user_version did not return any rows!")
|
return fmt.Errorf("sql.Rows.Next (user_version): PRAGMA user_version did not return any rows")
|
||||||
}
|
}
|
||||||
if err = rows.Scan(&userVersion); err != nil {
|
if err = rows.Scan(&userVersion); err != nil {
|
||||||
return errors.Wrap(err, "sql.Rows.Scan (user_version)")
|
return errors.Wrap(err, "sql.Rows.Scan (user_version)")
|
||||||
|
Loading…
Reference in New Issue
Block a user