Created
December 29, 2018 05:59
-
-
Save JenHsuan/6f13c0e9f66abf56031aaa737e9d8f89 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/julienschmidt/httprouter" | |
) | |
func Car(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
w.Header().Set("Mcleod-Key", "this is from mcleod") | |
w.Header().Set("Content-Type", "text/html; charset=utf-8") | |
fmt.Fprintf(w, "<h1>car</h1>") | |
myType, _ := r.URL.Query()["type"] | |
fmt.Fprintf(w, "<div>Path: %s</div>", ps.ByName("path")) | |
fmt.Fprintf(w, "<div>Hello %s</div>", myType[0]) | |
} | |
func main() { | |
mux := httprouter.New() | |
mux.GET("/car/:path", Car) | |
http.ListenAndServe(":8080", mux) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment