Last active
July 23, 2018 10:48
-
-
Save fwojciec/7017b0124059317e95c2814d31f96cfd to your computer and use it in GitHub Desktop.
My solution to "Exercise Hello, {you}" from Section 02 of Francesc Campoy's Go Web Workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/campoy/go-web-workshop/blob/master/section02/README.md | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/gorilla/mux" | |
) | |
func helloName(w http.ResponseWriter, r *http.Request) { | |
name := mux.Vars(r)["name"] | |
fmt.Fprintf(w, "Hello, %s", name) | |
} | |
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/hello/{name}", helloName) | |
http.Handle("/", r) | |
if err := http.ListenAndServe("127.0.0.1:8080", nil); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment