package main import ( "fmt" "net/http" ) func homeHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf8") fmt.Fprint(w, "

Welcome to my awesome site!

") } func contactHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf8") fmt.Fprint(w, "

Contact Page

To get in touch, email me at example@example.com

") } func faqHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf8") fmt.Fprint(w, `

FAQ


Is this a real website?

No.

I Can Has Cheezburger?

No.

`) } type Router struct{} func (router Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/": homeHandler(w, r) case "/contact": contactHandler(w, r) case "/faq": faqHandler(w, r) default: w.Header().Set("Content-Type", "text/html; charset=utf8") w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "404 page not found") } fmt.Fprintf(w, "

%s

", r.URL.Path) } func main() { var router Router fmt.Println("Starting the server on :3000...") http.ListenAndServe(":3000", router) }