go-todos-app/main.go
Michael Thomson 3d29dadaf3
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/dryrun Pipeline was successful
ci/woodpecker/push/publish-tag Pipeline was successful
ci/woodpecker/push/publish-latest Pipeline was successful
update: service, handlers, and db separation
2024-06-14 17:49:56 -04:00

36 lines
841 B
Go

package main
import (
"log"
"net/http"
"michaelthomson.dev/mthomson/go-todos-app/db"
"michaelthomson.dev/mthomson/go-todos-app/handlers"
"michaelthomson.dev/mthomson/go-todos-app/services"
)
func main() {
todosStore := db.NewTodoStore()
ts := services.NewTodoService(&todosStore)
homeHandler := handlers.NewHomeHandler(*ts)
todoHandler := handlers.NewTodoHandler(*ts)
router := http.NewServeMux()
// Serve static files
fs := http.FileServer(http.Dir("./assets"))
router.Handle("GET /assets/", http.StripPrefix("/assets/", fs))
router.HandleFunc("GET /{$}", homeHandler.Home)
router.HandleFunc("POST /todos", todoHandler.Create)
router.HandleFunc("DELETE /todos/{id}", todoHandler.Delete)
server := http.Server{
Addr: "localhost:3000",
Handler: router,
}
log.Fatal(server.ListenAndServe())
}