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
+8.5k Golang : Web(Javascript) to server-side websocket example
+5.4k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+9.3k Golang : Get login name from environment and prompt for password
+29k Golang : How to verify uploaded file is image or allowed file types
+10.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+6.5k Golang : How to handle file size larger than available memory panic issue
+32.9k Golang : Proper way to set function argument default value
+5k Golang : Use NLP to get sentences for each paragraph example
+8.5k Golang : How to get garbage collection data?
+11.4k Golang : How to check if a string starts or ends with certain characters or words?
+7.3k Golang : Variadic function arguments sanity check example
+9.9k Golang : Create Temporary File