Last active
January 6, 2019 05:30
-
-
Save JenHsuan/a1564fe82ecc09e2001d9503ec48fd76 to your computer and use it in GitHub Desktop.
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
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