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
+12.6k Golang : How to determine if a year is leap year?
+40.5k Golang : Convert []byte to image
+3.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+9.8k Golang : Removes punctuation or defined delimiter from the user's input
+8.9k Golang : Channels and buffered channels examples
+6.1k Golang : Validate credit card example
+10k Golang : How to use if, eq and print properly in html template
+8.7k Golang : Sort and reverse sort a slice of floats
+18.8k Golang : Read directory content with os.Open
+10.2k Golang : Post data with url.Values{}
+12.3k Golang : Get constant name from value