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.6k Golang : Regular Expression find string example
+21k Curl usage examples with Golang
+16.6k Golang : Capture stdout of a child process and act according to the result
+22.4k Golang : Round float to precision example
+15.2k Golang : Force download file example
+7.1k Golang : Word limiter example
+9.2k Facebook : Getting the friends list with PHP return JSON format
+30.5k Golang : Interpolating or substituting variables in string examples
+11.3k Golang : Secure file deletion with wipe example
+33.6k Golang : Proper way to set function argument default value
+4.6k Golang : A program that contain another program and executes it during run-time