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
+5.9k Golang : Generate human readable password
+6.3k Golang : Handle Palindrome string with case sensitivity and unicode
+11.6k Golang : How to check if a file is hidden?
+6.2k Golang : Reverse text lines or flip line order example
+4.6k Javascript : Generate random key with specific length
+16.8k Android Studio : AlertDialog and EditText to get user string input example
+6k Javascript : How to check a browser's Do Not Track status?
+15.4k Golang : Implement getters and setters
+8.2k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+11.7k Golang : Google Drive API upload and rename example
+9.8k Golang : Determine if time variables have same calendar day
+8.9k Golang : Web routing/multiplex example