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
+9.4k Golang : Copy map(hash table) example
+8.2k Golang : Generate Datamatrix barcode
+14k Golang : How to pass map to html template and access the map's elements
+34.2k Golang : Smarter Error Handling with strings.Contains()
+54.8k Golang : Unmarshal JSON from http response
+18.3k Golang : Iterating Elements Over A List
+19k Mac OSX : Homebrew and Golang
+18.4k Golang : Display list of time zones with GMT
+21.8k Golang : Convert seconds to minutes and remainder seconds
+14.9k Golang : Accurate and reliable decimal calculations
+7.3k Golang : Get YouTube playlist
+9.8k Golang : Get escape characters \u form from unicode characters