Skip to content

Instantly share code, notes, and snippets.

@ian-kent
Created December 10, 2014 10:51
Show Gist options
  • Save ian-kent/9dc88c17a20bae826bb5 to your computer and use it in GitHub Desktop.
Save ian-kent/9dc88c17a20bae826bb5 to your computer and use it in GitHub Desktop.
Gorilla pat placeholder/query param example
package main
import(
"log"
"net/http"
"github.com/gorilla/pat"
)
func main() {
p := pat.New()
p.Path("/foo/{bar}").Methods("GET").HandlerFunc(test)
http.Handle("/", p)
http.ListenAndServe(":1550", nil)
}
func test(w http.ResponseWriter, req *http.Request) {
log.Println(req.URL)
log.Println("Bar:", req.URL.Query().Get("bar"))
log.Println(":Bar:", req.URL.Query().Get(":bar"))
log.Println("Quack:", req.URL.Query().Get("quack"))
w.WriteHeader(200)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment