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
+11k Golang : Generate DSA private, public key and PEM files example
+28.9k Golang : Login(Authenticate) with Facebook example
+13.3k Golang : Human readable time elapsed format such as 5 days ago
+4.7k Python : Create Whois client or function example
+14.7k Golang : Get timezone offset from date or timestamp
+14.9k Golang : invalid character ',' looking for beginning of value
+27.6k Golang : Change a file last modified date and time
+7.9k Golang : Implementing class(object-oriented programming style)
+12.7k Android Studio : Password input and reveal password example
+5.6k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+17.4k Golang : Get all upper case or lower case characters from string example
+22.5k Golang : Get ASCII code from a key press(cross-platform) example