Skip to content

Commit 281846d

Browse files
committed
linting: add linter and vet workflows
1 parent a5ce114 commit 281846d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

Diff for: .github/workflows/pre-main.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test Incoming Changes
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
lint-and-vet:
10+
runs-on: ubuntu-22.04
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Run make vet
22+
run: make vet
23+
24+
- name: Run linter
25+
uses: golangci/golangci-lint-action@v7
26+
with:
27+
args: --timeout 10m0s

Diff for: pkg/database.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func insertQuayData(db *sql.DB, datetime string, count int, kind string) error {
4242
return fmt.Errorf("invalid input: datetime=%v, kind=%v, count=%d (datetime/kind cannot be empty, count cannot be negative)", datetime, kind, count)
4343

4444
}
45-
45+
4646
parsedDate, err := time.Parse("Mon, 02 Jan 2006 15:04:05 -0700", datetime)
4747
if err != nil {
4848
return fmt.Errorf("invalid datetime format: %v, expected YYYY-MM-DD", datetime)
@@ -67,7 +67,7 @@ func insertQuayData(db *sql.DB, datetime string, count int, kind string) error {
6767
func pingDB(db *sql.DB) error {
6868
logrus.Info("Pinging the database to verify connection...")
6969
if err := db.Ping(); err != nil {
70-
db.Close()
70+
_ = db.Close()
7171
return fmt.Errorf("database ping failed: %w", err)
7272
}
7373
logrus.Info("Database connection verified successfully.")
@@ -185,7 +185,11 @@ func initDBAWS() (*sql.DB, error) {
185185
}
186186

187187
// Close the initial connection and reconnect with the specified database.
188-
db.Close()
188+
err = db.Close()
189+
if err != nil {
190+
return nil, fmt.Errorf("failed to close initial connection: %w", err)
191+
}
192+
189193
DBUsername := os.Getenv("DB_USER")
190194
DBPassword := os.Getenv("DB_PASSWORD")
191195
DBURL := os.Getenv("DB_URL")
@@ -230,7 +234,11 @@ func ConnectToLocalDB() (*sql.DB, error) {
230234
if err != nil {
231235
return nil, fmt.Errorf("failed to connect to MySQL server: %w", err)
232236
}
233-
defer db.Close()
237+
defer func() {
238+
if err := db.Close(); err != nil {
239+
logrus.Errorf("failed to close MySQL connection: %v", err)
240+
}
241+
}()
234242

235243
// Check if the database exists
236244
var exists int

0 commit comments

Comments
 (0)