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
+5.9k Golang : Takes a plural word and makes it singular
+14.1k Golang : How do I get the local IP (non-loopback) address ?
+6.7k Golang : Reverse a string with unicode
+8k Golang : Inject/embed Javascript before sending out to browser example
+9.7k Golang : Sieve of Eratosthenes algorithm
+12.9k Golang : Google Drive API upload and rename example
+4.3k Javascript : Change page title to get viewer attention
+7.1k Golang : HTTP Server Example
+17.7k Golang : Read input from console line
+18.9k Nginx + FastCGI + Go Setup.
+6.4k Golang : Create zip/ePub file without compression(use Store algorithm)