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.1k Swift : Convert (cast) String to Double
+12.5k Golang : Verify token from Google Authenticator App
+6k How to let Facebook Login button redirect to a particular URL ?
+26.1k Golang : Convert CSV data to JSON format and save to file
+11.1k Golang : Convert a rune to unicode style string \u
+22k Golang : Gorilla mux routing example
+10.4k Golang : Post data with url.Values{}
+5.1k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+9.4k Golang : Convert file unix timestamp to UTC time example
+7.1k Golang : Check from web if Go application is running or not
+50.3k Golang : Check if item is in slice/array
+3.5k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example