This commit is contained in:
2025-02-10 12:33:01 -05:00
parent 608f7c36e7
commit 5df204164e
9 changed files with 160 additions and 10 deletions

View File

@@ -10,9 +10,10 @@ import (
"gitea.michaelthomson.dev/mthomson/habits/internal/middleware"
"gitea.michaelthomson.dev/mthomson/habits/internal/migrate"
todohandler "gitea.michaelthomson.dev/mthomson/habits/internal/todo/handler"
todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/sqlite"
todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/postgres"
todoservice "gitea.michaelthomson.dev/mthomson/habits/internal/todo/service"
_ "github.com/mattn/go-sqlite3"
_ "github.com/jackc/pgx/v5/stdlib"
)
func main() {
@@ -23,18 +24,18 @@ func main() {
loggingMiddleware := middleware.LoggingMiddleware(httpLogger)
// create db pool
db, err := sql.Open("sqlite3", "./habits.db")
postgresUrl := "postgres://todo:password@localhost:5432/todo"
db, err := sql.Open("pgx", postgresUrl)
if err != nil {
log.Fatal("Failed to open db pool")
}
defer db.Close()
// run migrations
migrate.Migrate(db)
// create repos
todoRepository := todorepository.NewSqliteTodoRepository(db)
todoRepository := todorepository.NewPostgresTodoRepository(db)
// create services
todoService := todoservice.NewTodoService(todoRepository)