Compare commits
No commits in common. "2d2bea65434eda424a6b1968a89e44377eea6e40" and "0afafd97fdb24a031dc12e39a5c860a669e694d0" have entirely different histories.
2d2bea6543
...
0afafd97fd
20
main.go
20
main.go
@ -13,28 +13,13 @@ func contactHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
fmt.Fprint(w, "<h1>Contact Page</h1><p>To get in touch, email me at <a href=\"mailto:example@example.com\">example@example.com</a></p>")
|
fmt.Fprint(w, "<h1>Contact Page</h1><p>To get in touch, email me at <a href=\"mailto:example@example.com\">example@example.com</a></p>")
|
||||||
}
|
}
|
||||||
func faqHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
|
||||||
fmt.Fprint(w, `
|
|
||||||
<h1>FAQ</h1>
|
|
||||||
<hr>
|
|
||||||
<h3>Is this a real website?</h3>
|
|
||||||
<p>No.</p>
|
|
||||||
<h3>I Can Has Cheezburger?</h3>
|
|
||||||
<p>No.</p>
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Router struct{}
|
var pathHandler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (router Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/":
|
case "/":
|
||||||
homeHandler(w, r)
|
homeHandler(w, r)
|
||||||
case "/contact":
|
case "/contact":
|
||||||
contactHandler(w, r)
|
contactHandler(w, r)
|
||||||
case "/faq":
|
|
||||||
faqHandler(w, r)
|
|
||||||
default:
|
default:
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
@ -44,7 +29,6 @@ func (router Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var router Router
|
|
||||||
fmt.Println("Starting the server on :3000...")
|
fmt.Println("Starting the server on :3000...")
|
||||||
http.ListenAndServe(":3000", router)
|
http.ListenAndServe(":3000", pathHandler)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user