30 lines
636 B
Go
30 lines
636 B
Go
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!")
|
|
}
|