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.8k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+14.6k Golang : Overwrite previous output with count down timer
+9k Golang : Go as a script or running go with shebang/hashbang style
+5.1k Linux : How to set root password in Linux Mint
+7.5k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+30.9k Golang : Interpolating or substituting variables in string examples
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+9.1k Golang : Capture text return from exec function example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+16k Golang : Read large file with bufio.Scanner cause token too long error
+7.1k Restart Apache or Nginx web server without password prompt