Created
December 10, 2014 10:51
-
-
Save ian-kent/9dc88c17a20bae826bb5 to your computer and use it in GitHub Desktop.
Gorilla pat placeholder/query param example
This file contains hidden or 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( | |
"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