Fix monitoring PF CI lint issues
This commit is contained in:
@@ -137,6 +137,14 @@ func (a *App) Close() error {
|
||||
return a.DB.Close()
|
||||
}
|
||||
|
||||
func closeRows(rows *sql.Rows) {
|
||||
_ = rows.Close()
|
||||
}
|
||||
|
||||
func rollbackTx(tx *sql.Tx) {
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
|
||||
func (a *App) InitDB(ctx context.Context) error {
|
||||
stmts := []string{
|
||||
`CREATE TABLE IF NOT EXISTS employees (
|
||||
@@ -210,7 +218,7 @@ func (a *App) migrateEmployees(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
columns := map[string]bool{}
|
||||
for rows.Next() {
|
||||
var cid int
|
||||
@@ -237,7 +245,7 @@ func (a *App) migrateCompetitorListings(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
columns := map[string]bool{}
|
||||
for rows.Next() {
|
||||
var cid int
|
||||
@@ -325,15 +333,6 @@ func enumStatusOut(value string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func enumStatusIn(value string) string {
|
||||
switch strings.ToLower(value) {
|
||||
case "removed":
|
||||
return "REMOVED"
|
||||
default:
|
||||
return "ACTIVE"
|
||||
}
|
||||
}
|
||||
|
||||
func timeOut(raw sql.NullString) *string {
|
||||
if !raw.Valid || strings.TrimSpace(raw.String) == "" {
|
||||
return nil
|
||||
|
||||
@@ -57,7 +57,7 @@ func (a *App) ListEmployees(ctx context.Context, isAdmin bool, current *Employee
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
return scanEmployees(rows)
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ func (a *App) ListProjects(ctx context.Context, ownerID int64) ([]Project, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
items := []Project{}
|
||||
for rows.Next() {
|
||||
p, err := a.scanProject(ctx, rows, false)
|
||||
@@ -353,7 +353,7 @@ func (a *App) DeleteProject(ctx context.Context, ownerID, projectID int64) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
defer rollbackTx(tx)
|
||||
listingRows, err := tx.QueryContext(ctx, `SELECT id FROM competitor_listings WHERE project_id = ?`, projectID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -362,12 +362,12 @@ func (a *App) DeleteProject(ctx context.Context, ownerID, projectID int64) error
|
||||
for listingRows.Next() {
|
||||
var id int64
|
||||
if err := listingRows.Scan(&id); err != nil {
|
||||
listingRows.Close()
|
||||
closeRows(listingRows)
|
||||
return err
|
||||
}
|
||||
listingIDs = append(listingIDs, id)
|
||||
}
|
||||
listingRows.Close()
|
||||
closeRows(listingRows)
|
||||
for _, id := range listingIDs {
|
||||
if _, err := tx.ExecContext(ctx, `DELETE FROM price_history WHERE listing_id = ?`, id); err != nil {
|
||||
return err
|
||||
@@ -392,7 +392,7 @@ func (a *App) DeleteListing(ctx context.Context, ownerID, listingID int64) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
defer rollbackTx(tx)
|
||||
if _, err := tx.ExecContext(ctx, `
|
||||
DELETE FROM price_history
|
||||
WHERE listing_id IN (
|
||||
@@ -508,10 +508,10 @@ func (a *App) ListingsForProject(ctx context.Context, projectID int64, withHisto
|
||||
items = append(items, *item)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
rows.Close()
|
||||
closeRows(rows)
|
||||
return nil, err
|
||||
}
|
||||
rows.Close()
|
||||
closeRows(rows)
|
||||
if withHistory {
|
||||
for i := range items {
|
||||
history, err := a.PriceHistory(ctx, items[i].ID)
|
||||
@@ -562,7 +562,7 @@ func (a *App) TeamOverview(ctx context.Context, portalUserIDs []string, all bool
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
items := []TeamOverviewRow{}
|
||||
for rows.Next() {
|
||||
var item TeamOverviewRow
|
||||
@@ -614,7 +614,7 @@ func (a *App) PriceHistory(ctx context.Context, listingID int64) ([]PricePoint,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
defer closeRows(rows)
|
||||
out := []PricePoint{}
|
||||
for rows.Next() {
|
||||
var p PricePoint
|
||||
|
||||
Reference in New Issue
Block a user