Skip to content

Instantly share code, notes, and snippets.

@JenHsuan
Created December 29, 2018 05:59
Show Gist options
  • Save JenHsuan/6f13c0e9f66abf56031aaa737e9d8f89 to your computer and use it in GitHub Desktop.
Save JenHsuan/6f13c0e9f66abf56031aaa737e9d8f89 to your computer and use it in GitHub Desktop.
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