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
+10.3k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+21.5k Golang : Join arrays or slices example
+8.5k Golang : Random integer with rand.Seed() within a given range
+11.6k Golang : Sort and reverse sort a slice of runes
+10.2k Golang : Get local time and equivalent time in different time zone
+20.3k Golang : Saving private and public key to files
+17.3k Golang : How to make a file read only and set it to writable again?
+6.5k Android Studio : Hello World example
+7.8k Golang : Multiplexer with net/http and map
+13.4k Golang : Check if an integer is negative or positive
+7.5k Golang : Scan files for certain pattern and rename part of the files
+11.6k Golang : Convert a rune to unicode style string \u