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.5k Golang : How to get year, month and day?
+7.5k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+12.9k How to automatically restart your crashed Golang server
+41.1k Golang : Get hardware information such as disk, memory and CPU usage
+18.8k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+3.2k Golang : PGX CopyFrom to insert rows into Postgres database
+13.3k Golang : Find network of an IP address
+8.3k Golang : Detect number of active displays and the display's resolution
+17.8k Golang : Read input from console line
+8.1k Golang : Generate random Chinese, Japanese, Korean and other runes
+6.9k Javascript : How to check a browser's Do Not Track status?
+4.6k Golang : Shortening import identifier