2025-11-11 11:13:38 +01:00

31 lines
920 B
Go

package main
// This file is the one place in your application where all routes are listed.
import (
"context"
"crud/api"
"crud/sqlite"
"html/template"
"io/fs"
"net/http"
)
// addRoutes combines the URL endpoints with the applications's services
// and dependencies and required middleware
func addRoutes(
ctx context.Context,
mux *http.ServeMux,
database *sqlite.Database,
static fs.FS,
templ *template.Template,
) {
mux.Handle("GET /", http.FileServer(http.FS(static)))
mux.Handle("GET /board", api.Board(ctx, database, templ))
mux.Handle("GET /edit-record/{id}", api.EditRecord(ctx, database, templ))
mux.Handle("PATCH /patch-record/{id}", api.PatchRecord(ctx, database, templ))
mux.Handle("DELETE /delete-record/{id}", api.DeleteRecord(ctx, database, templ))
mux.Handle("GET /html/{id}", api.EditRecord(ctx, database, templ))
mux.Handle("GET /json/{id}", api.RecordJson(ctx, database, templ))
}