re-write with std usage of net/http
This commit is contained in:
parent
c107d94b11
commit
81bc046237
10 changed files with 419 additions and 97 deletions
30
handlers/routes.go
Normal file
30
handlers/routes.go
Normal 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!")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue