re-write with std usage of net/http

This commit is contained in:
Sebastian Cabrera 2025-06-11 15:49:47 -04:00
parent c107d94b11
commit 81bc046237
Signed by: okseby
GPG key ID: DA858232740D0404
10 changed files with 419 additions and 97 deletions

30
handlers/routes.go Normal file
View file

@ -0,0 +1,30 @@
package handlers
import (
"fmt"
"net/http"
)
func RegisterRoutes() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", serveIndex)
mux.HandleFunc("/hello", helloHandler)
mux.HandleFunc("/goodbye", goodbyeHandler)
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
return mux
}
func serveIndex(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/index.html")
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, world!")
}
func goodbyeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Goodbye, world!")
}