Golang : Gorrila mux.Vars() function example
Gorrila Web toolkit mux.Vars() function usage example. Vars contains the URI variables of the current request.
For example :
URL : http://website:8080/person/Boo/CEO/199 and processed by
mx.HandleFunc("/person/{name}/{job}/{age:[0-199]+}", ProcessPathVariables)
Vars will returns the name
, job
and age
from r *http.Request
func ProcessPathVariables(w http.ResponseWriter, r *http.Request) {
// break down the variables for easier assignment
vars := mux.Vars(r)
name := vars["name"]
job := vars["job"]
age := vars["age"]
w.Write([]byte(fmt.Sprintf("Name is %s ", name)))
w.Write([]byte(fmt.Sprintf("Job is %s ", job)))
w.Write([]byte(fmt.Sprintf("Age is %s ", age)))
}
Reference :
See also : Golang : Gorilla mux routing example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+12.3k Golang : Activate web camera and broadcast out base64 encoded images
+9.7k Golang : How to determine a prime number?
+21k Golang : How to read JPG(JPEG), GIF and PNG files ?
+7.6k Golang : Find network service name from given port and protocol
+29.7k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+8.3k Golang : Copy map(hash table) example
+5.1k Golang : Experimental emojis or emoticons icons programming language
+4.1k Python : Convert(cast) string to bytes example
+10.1k Golang : GTK Input dialog box examples
+15.7k Golang : XML to JSON example
+27.7k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+4.7k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error