Skip to content

Instantly share code, notes, and snippets.

@dlsniper
Created February 11, 2015 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlsniper/40ad1d2e1a4cf14d04be to your computer and use it in GitHub Desktop.
Save dlsniper/40ad1d2e1a4cf14d04be to your computer and use it in GitHub Desktop.
Example on how to get URL parameters
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