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
+15.9k Golang : How to save log messages to file?
+20.8k Golang : Read directory content with filepath.Walk()
+11.9k Golang : Linear algebra and matrix calculation example
+4.8k Golang : Find change in a combination of coins example
+4.7k PHP : Get client IP address
+23.1k Golang : GORM read from database example
+7.4k Golang : How to capture return values from goroutines?
+11.3k Golang : "https://" not allowed in import path
+4.8k Golang : Launching your executable inside a console under Linux
+8.2k Golang : Read file with ioutil
+3.9k PHP : Extract part of a string starting from the middle
+12.8k Golang : Get uploaded file name or access uploaded files