Skip to content

Instantly share code, notes, and snippets.

@JenHsuan
Last active January 6, 2019 05:30
Show Gist options
  • Save JenHsuan/a1564fe82ecc09e2001d9503ec48fd76 to your computer and use it in GitHub Desktop.
Save JenHsuan/a1564fe82ecc09e2001d9503ec48fd76 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func Car(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
vars := mux.Vars(r)
fmt.Fprintf(w, "<h1>car</h1>")
fmt.Fprintf(w, "<div>Path: %v</div>", vars["path"])
fmt.Fprintf(w, "<div>Hello %v</div>", vars["type"])
}
func main() {
mux := mux.NewRouter()
mux.Path("/car/{path}").Queries("type", "{type}").HandlerFunc(Car).Methods("GET").Name("Car")
http.ListenAndServe(":8080", mux)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment