Skip to content

Commit

Permalink
rewrite connect check
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Polyakov committed Jun 8, 2024
1 parent 9e21aea commit c4406b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Lint the code with golangci-lint
lint:
go fmt ./...
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:latest golangci-lint run -v

# Install requirements
Expand Down
19 changes: 9 additions & 10 deletions cmd/ctf01d/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
config "ctf01d/configs"
models "ctf01d/internal/app/db"
"ctf01d/internal/app/routers"
"database/sql"
"log/slog"
Expand All @@ -24,17 +23,17 @@ func main() {
slog.Info("Connecting to the database ...")
db, err := sql.Open(cfg.DB.Driver, cfg.DB.DataSource)
if err != nil {
slog.Error("Error connecting to the database: " + err.Error())
} else {
query := `SELECT update_id FROM database_updates WHERE id=(SELECT max(id) FROM database_updates)`
last_update := &models.DatabaseUpdate{}
err := db.QueryRow(query).Scan(&last_update.Id, &last_update.StartTime, &last_update.UpdateId, &last_update.Description)
if err != nil {
slog.Error("Problem with database: " + err.Error())
// return
}
slog.Error("Error opening database connection: " + err.Error())
return
}
defer db.Close()

if err := db.Ping(); err != nil {
slog.Error("Error pinging database: " + err.Error())
return
}
slog.Info("Database connection established successfully")

router := routers.NewRouter(db)
slog.Info("Server started on http://" + cfg.HTTP.Host + ":" + cfg.HTTP.Port)

Expand Down

0 comments on commit c4406b0

Please sign in to comment.