Golang : Query string with space symbol %20 in between
Problem :
You want to form URL that looks like this :
https://example.com/query?keyword="golang lookup"
but your final URL looks like this :
https://example.com/query?keyword="golang%20lookup"
How to get rid the %20
sign ?
Solution :
Use url.QueryEscape() function to escapes the string so it can be safely placed inside a URL query. For example :
func TagSearch(tag string) string {
return fmt.Sprintf("https://example.com/query?keyword=%s", url.QueryEscape(tag))
}
References :
See also : Golang : Get query string value on a POST request
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
+7.2k Golang : How to fix html/template : "somefile" is undefined error?
+32.3k Golang : Math pow(the power of x^y) example
+6k Golang : Experimenting with the Rejang script
+6k Java : Human readable password generator
+13.9k Golang : concatenate(combine) strings
+21.1k Golang : Convert(cast) string to rune and back to string example
+9.6k Golang : List available AWS regions
+9.9k CodeIgniter : Load different view for mobile devices
+10.2k Golang : Convert file content to Hex
+5.4k Golang : Display advertisement images or strings on random order
+11.6k Golang : Convert(cast) float to int
+35.2k Golang : Strip slashes from string example