index — crispy-website @ 1d63bc89849eb0026246a9e4fa44001b4ef9445c

My personal homepage (very crispy)

main: make handler dynamic
crispy-caesus crispy@crispy-caesus.eu
Fri, 27 Feb 2026 00:35:38 +0100
commit

1d63bc89849eb0026246a9e4fa44001b4ef9445c

parent

92463ef2b4d8053dc229ccd9eb5a64878047eee6

1 files changed, 11 insertions(+), 7 deletions(-)

jump to
M cmd/server/main.gocmd/server/main.go

@@ -6,18 +6,22 @@ "log"

"net/http" ) +func handler(w http.ResponseWriter, r *http.Request) { + title := r.URL.Path[len("/"):] + if title == "" { + title = "index" + } + log.Print(title) + http.ServeFile(w, r, "templates/" + title + ".html") +} + + func main() { fs := http.FileServer(http.Dir("static")) http.Handle("/static/", http.StripPrefix("/static/", fs)) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "templates/index.html") - }) - - http.HandleFunc("/music", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "templates/music.html") - }) + http.HandleFunc("/", handler) fmt.Println("Running on :8080") log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))