package main import ( "database/sql" "log" "net/http" "gitea.michaelthomson.dev/mthomson/habits/internal/migrate" todohandler "gitea.michaelthomson.dev/mthomson/habits/internal/todo/handler" todosqliterepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/sqlite" todoservice "gitea.michaelthomson.dev/mthomson/habits/internal/todo/service" _ "github.com/mattn/go-sqlite3" ) func main() { // create db pool db, err := sql.Open("sqlite3", "./habits.db") if err != nil { log.Fatal("Failed to open db pool") } defer db.Close() // run migrations migrate.Migrate(db) // create repos todoRepository := todosqliterepository.NewSqliteTodoRepository(db) // create services todoService := todoservice.NewTodoService(todoRepository) // create mux mux := http.NewServeMux() // register handlers mux.Handle("GET /todo/{id}", todohandler.HandleTodoGet(todoService)) mux.Handle("POST /todo", todohandler.HandleTodoCreate(todoService)) mux.Handle("DELETE /todo/{id}", todohandler.HandleTodoDelete(todoService)) mux.Handle("PUT /todo/{id}", todohandler.HandleTodoUpdate(todoService)) // create server server := &http.Server{ Addr: ":8080", Handler: mux, } server.ListenAndServe() }