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.2k Golang : How to display image file or expose CSS, JS files from localhost?
+8k Golang : Append and add item in slice
+7.3k Golang : Word limiter example
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+13.1k Golang : How to get a user home directory path?
+17.5k Golang : Clone with pointer and modify value
+9.4k Golang : Get all countries currencies code in JSON format
+18.1k Golang : Put UTF8 text on OpenCV video capture image frame
+19.2k Golang : Delete item from slice based on index/key position
+18.6k Golang : Iterating Elements Over A List
+18.7k Golang : Delete duplicate items from a slice/array
+13.7k Golang : Convert spaces to tabs and back to spaces example