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
+18k Golang : Iterate linked list example
+5.5k Golang : How to deal with configuration data?
+9.6k Golang : Get all countries currencies code in JSON format
+13k Golang : Convert IPv4 address to packed 32-bit binary format
+17.8k Convert JSON to CSV in Golang
+41.6k Golang : Convert string to array/slice
+10.3k Golang : Identifying Golang HTTP client request
+4.9k Golang : How to pass data between controllers with JSON Web Token
+5.1k Python : Convert(cast) bytes to string example
+20k Golang : Append content to a file
+6.1k Unix/Linux : How to open tar.gz file ?
+25.5k Golang : Convert uint value to string type