chore: make golangci-lint happy

This commit is contained in:
Steven
2022-08-24 21:53:12 +08:00
parent 0e4e2e4bc5
commit 7d0407013e
14 changed files with 130 additions and 35 deletions

View File

@@ -14,8 +14,6 @@ import (
"github.com/usememos/memos/common"
"github.com/usememos/memos/server/profile"
_ "github.com/mattn/go-sqlite3"
)
//go:embed migration
@@ -175,11 +173,7 @@ func (db *DB) applyMigrationForMinorVersion(ctx context.Context, minorVersion st
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
return tx.Commit()
}
func (db *DB) seed(ctx context.Context) error {
@@ -204,7 +198,7 @@ func (db *DB) seed(ctx context.Context) error {
return nil
}
// excecute runs a single SQL statement within a transaction.
// execute runs a single SQL statement within a transaction.
func (db *DB) execute(ctx context.Context, stmt string) error {
tx, err := db.Db.Begin()
if err != nil {
@@ -216,11 +210,7 @@ func (db *DB) execute(ctx context.Context, stmt string) error {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
return tx.Commit()
}
// minorDirRegexp is a regular expression for minor version directory.
@@ -264,9 +254,5 @@ func (db *DB) createMigrationHistoryTable(ctx context.Context) error {
return err
}
if err := tx.Commit(); err != nil {
return err
}
return nil
return tx.Commit()
}

View File

@@ -33,9 +33,10 @@ func (db *DB) FindMigrationHistory(ctx context.Context, find *MigrationHistoryFi
if len(list) == 0 {
return nil, nil
} else {
return list[0], nil
}
migrationHistory := list[0]
return migrationHistory, nil
}
func (db *DB) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {
@@ -92,6 +93,10 @@ func findMigrationHistoryList(ctx context.Context, tx *sql.Tx, find *MigrationHi
migrationHistoryList = append(migrationHistoryList, &migrationHistory)
}
if err := rows.Err(); err != nil {
return nil, err
}
return migrationHistoryList, nil
}
@@ -121,5 +126,9 @@ func upsertMigrationHistory(ctx context.Context, tx *sql.Tx, upsert *MigrationHi
return nil, err
}
if err := row.Err(); err != nil {
return nil, err
}
return &migrationHistory, nil
}

View File

@@ -95,6 +95,10 @@ func findMemoOrganizer(ctx context.Context, tx *sql.Tx, find *api.MemoOrganizerF
return nil, FormatError(err)
}
if err := row.Err(); err != nil {
return nil, err
}
return &memoOrganizerRaw, nil
}

View File

@@ -7,14 +7,14 @@ import (
"github.com/usememos/memos/server/profile"
)
// Store provides database access to all raw objects
// Store provides database access to all raw objects.
type Store struct {
db *sql.DB
profile *profile.Profile
cache api.CacheService
}
// New creates a new instance of Store
// New creates a new instance of Store.
func New(db *sql.DB, profile *profile.Profile) *Store {
cacheService := NewCacheService()

View File

@@ -258,6 +258,10 @@ func patchUser(ctx context.Context, tx *sql.Tx, patch *api.UserPatch) (*userRaw,
return nil, FormatError(err)
}
if err := row.Err(); err != nil {
return nil, err
}
return &userRaw, nil
}

View File

@@ -111,7 +111,7 @@ func findUserSettingList(ctx context.Context, tx *sql.Tx, find *api.UserSettingF
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.Key; v != nil {
where, args = append(where, "key = ?"), append(args, (*v).String())
where, args = append(where, "key = ?"), append(args, v.String())
}
where, args = append(where, "user_id = ?"), append(args, find.UserID)