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.1k Golang : Handle Palindrome string with case sensitivity and unicode
+16.9k Golang : Gzip file example
+5.8k List of Golang XML tutorials
+19.4k Golang : Check if directory exist and create if does not exist
+11.1k Nginx : TLS 1.2 support
+7k Golang : Calculate BMI and risk category
+20.4k Golang : Reset or rewind io.Reader or io.Writer
+6.8k Golang : How to determine if request or crawl is from Google robots
+21k Golang : Convert date string to variants of time.Time type examples
+8.4k Golang : Count leading or ending zeros(any item of interest) example
+7.9k Golang : Regular Expression find string example
+8.5k Your page has meta tags in the body instead of the head