36 lines
841 B
Go
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())
|
|
}
|