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
+4.2k Unix/Linux : secure copying between servers with SCP command examples
+6.3k Golang : File system scanning
+5.1k AWS S3 : Prevent Hotlinking policy
+16.5k Golang : Put UTF8 text on OpenCV video capture image frame
+12.7k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+9k Golang : Print how to use flag for your application example
+8.4k Golang : How to protect your source code from client, hosting company or hacker?
+8.1k Golang : Timeout example
+17.7k Golang : Calculate entire request body length during run time
+5.4k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+11.9k Golang : Handle or parse date string with Z suffix(RFC3339) example