Expanded linting + fix warnings (#1396)

* Expand the linters and types of warnings to improve consistency and safety

* Fail lint workflow if there are errors

* golint has been replaced by revive

* Hand-pick some of the default exclude list

* Ignore error when trying to delete preview gif

* Ignore linter warning opening playlist path

* Rename user field Id -> ID

* A bunch of renames to address linter warnings

* Rename ChatClient -> Client per linter suggestion best practice

* Rename ChatServer -> Server per linter suggestion best practice

* More linter warning fixes

* Add missing comments to all exported functions and properties
This commit is contained in:
Gabe Kangas
2021-09-12 00:18:15 -07:00
committed by GitHub
parent 70e9f4945f
commit c6c6f0233d
57 changed files with 331 additions and 186 deletions

View File

@@ -12,15 +12,15 @@ import (
"os"
"path/filepath"
_ "github.com/mattn/go-sqlite3"
"github.com/schollz/sqlite3dump"
log "github.com/sirupsen/logrus"
)
// Restore will attempt to restore the database using a specified backup file.
func Restore(backupFile string, databaseFile string) error {
log.Printf("Restoring database backup %s to %s", backupFile, databaseFile)
data, err := ioutil.ReadFile(backupFile)
data, err := ioutil.ReadFile(backupFile) // nolint
if err != nil {
return fmt.Errorf("Unable to read backup file %s", err)
}
@@ -38,7 +38,7 @@ func Restore(backupFile string, databaseFile string) error {
defer gz.Close()
rawSql := b.String()
rawSQL := b.String()
if _, err := os.Create(databaseFile); err != nil {
return errors.New("Unable to write restored database")
@@ -49,13 +49,14 @@ func Restore(backupFile string, databaseFile string) error {
if err != nil {
return err
}
if _, err := db.Exec(rawSql); err != nil {
if _, err := db.Exec(rawSQL); err != nil {
return err
}
return nil
}
// Backup will backup the provided instance of the database to the specified file.
func Backup(db *sql.DB, backupFile string) {
log.Traceln("Backing up database to", backupFile)
@@ -76,10 +77,10 @@ func Backup(db *sql.DB, backupFile string) {
handleError(err)
return
}
out.Flush()
_ = out.Flush()
// Create a new backup file
f, err := os.OpenFile(backupFile, os.O_WRONLY|os.O_CREATE, 0600)
f, err := os.OpenFile(backupFile, os.O_WRONLY|os.O_CREATE, 0600) // nolint
if err != nil {
handleError(err)
return