Created
February 11, 2015 21:36
-
-
Save dlsniper/40ad1d2e1a4cf14d04be to your computer and use it in GitHub Desktop.
Example on how to get URL parameters
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 demo(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "text/plain") | |
key := "demoKey" | |
fmt.Fprintf(w, "key: %s -> val: %#v\n", key, r.URL.Query().Get(key)) | |
key = "demo" | |
fmt.Fprintf(w, "key: %s -> val: %#v\n", key, r.URL.Query().Get(key)) | |
} | |
func main() { | |
router := mux.NewRouter() | |
router.StrictSlash(false) | |
router.HandleFunc("/demo", demo).Methods("GET") | |
http.Handle("/", router) | |
http.ListenAndServe("127.0.0.1:8088", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment