Browse Source

Step 4

step4
Levi Olson 6 years ago
parent
commit
91f6fe0497
1 changed files with 10 additions and 4 deletions
  1. +10
    -4
      main.go

+ 10
- 4
main.go View File

@ -7,15 +7,21 @@ import (
) )
func main() { 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)) 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") 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) 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)
}

Loading…
Cancel
Save