From 91f6fe04970b7d622e7ed52b53e5d0e593664041 Mon Sep 17 00:00:00 2001 From: Levi Olson Date: Wed, 9 May 2018 16:04:26 -0500 Subject: [PATCH] Step 4 --- main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1b84590..542ab48 100644 --- a/main.go +++ b/main.go @@ -7,15 +7,21 @@ import ( ) func main() { - http.HandleFunc("/hello", HelloHTTP) - http.HandleFunc("/", NotFound) + http.HandleFunc("/hello", helloHTTP) + http.HandleFunc("/user/", userProfile) + http.HandleFunc("/", notFound) log.Fatal(http.ListenAndServe(":8080", nil)) } -func HelloHTTP(w http.ResponseWriter, req *http.Request) { +func helloHTTP(w http.ResponseWriter, req *http.Request) { fmt.Fprint(w, "Hello HTTP") } -func NotFound(w http.ResponseWriter, req *http.Request) { +func notFound(w http.ResponseWriter, req *http.Request) { http.NotFound(w, req) } + +func userProfile(w http.ResponseWriter, req *http.Request) { + userID := req.URL.Path[len("/user/"):] + fmt.Fprintf(w, "User Profile: %q", userID) +}