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
+9k Golang : Generate random Chinese, Japanese, Korean and other runes
+6.9k Nginx : How to block user agent ?
+9.9k Golang : Get login name from environment and prompt for password
+13.8k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+8.9k Golang : Simple histogram example
+22.1k Golang : Read directory content with filepath.Walk()
+13.3k Golang : Strings comparison
+19.6k Golang : Append content to a file
+10.5k Android Studio : Checkbox for user to select options example
+9.2k Mac OSX : Get a process/daemon status information
+6k Linux/Unix : Commands that you need to be careful about
+8k Golang : Configure Apache and NGINX to access your Go service example