Skip to content

Instantly share code, notes, and snippets.

@fwojciec
Last active July 23, 2018 10:48
Show Gist options
  • Save fwojciec/7017b0124059317e95c2814d31f96cfd to your computer and use it in GitHub Desktop.
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
// 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