feat: use sqlx
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 6m59s

This commit is contained in:
2025-05-04 15:17:48 +02:00
parent af89aa8639
commit b20a48be25
15 changed files with 165 additions and 190 deletions

16
main.go
View File

@@ -9,7 +9,6 @@ import (
"spend-sparrow/types"
"context"
"database/sql"
"net/http"
"os"
"os/signal"
@@ -17,6 +16,7 @@ import (
"syscall"
"time"
"github.com/jmoiron/sqlx"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -28,7 +28,7 @@ func main() {
log.Fatal("Error loading .env file")
}
db, err := sql.Open("sqlite3", "./data.db")
db, err := sqlx.Open("sqlite3", "./data.db")
if err != nil {
log.Fatal("Could not open Database data.db: %v", err)
}
@@ -37,7 +37,7 @@ func main() {
run(context.Background(), db, os.Getenv)
}
func run(ctx context.Context, database *sql.DB, env func(string) string) {
func run(ctx context.Context, database *sqlx.DB, env func(string) string) {
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer cancel()
@@ -100,26 +100,26 @@ func shutdownServer(s *http.Server, ctx context.Context, wg *sync.WaitGroup) {
}
}
func createHandler(d *sql.DB, serverSettings *types.Settings) http.Handler {
func createHandler(d *sqlx.DB, serverSettings *types.Settings) http.Handler {
var router = http.NewServeMux()
authDb := db.NewAuthSqlite(d)
workoutDb := db.NewWorkoutDbSqlite(d)
accountDb := db.NewAccountSqlite(d)
randomService := service.NewRandomImpl()
clockService := service.NewClockImpl()
mailService := service.NewMailImpl(serverSettings)
authService := service.NewAuthImpl(authDb, randomService, clockService, mailService, serverSettings)
workoutService := service.NewWorkoutImpl(workoutDb, randomService, clockService, mailService, serverSettings)
accountService := service.NewAccountImpl(accountDb, randomService, clockService, serverSettings)
render := handler.NewRender()
indexHandler := handler.NewIndex(authService, render)
authHandler := handler.NewAuth(authService, render)
workoutHandler := handler.NewWorkout(workoutService, authService, render)
accountHandler := handler.NewAccount(accountService, authService, render)
indexHandler.Handle(router)
workoutHandler.Handle(router)
accountHandler.Handle(router)
authHandler.Handle(router)
// Serve static files (CSS, JS and images)