Is there an example and use of url.QueryEscape? for golang

How to understand and use url.QueryEscape in Go language?

+7
go
source share
1 answer

To understand the use of url.QueryEscape , you first need to understand what the url query string is .

The query string is part of a URL that contains data that can be passed to web applications. This data must be encoded, and this encoding is done using url.QueryEscape . It performs what is called URL encoding .

Example

Let's say we have a webpage:

 http://mywebpage.com/thumbify 

And we want to pass the image url, http://images.com/cat.png , into this web application. Then this URL should look something like this:

 http://mywebpage.com/thumbify?image=http%3A%2F%2Fimages.com%2Fcat.png 

In Go code, it will look like this:

 package main import ( "fmt" "net/url" ) func main() { webpage := "http://mywebpage.com/thumbify" image := "http://images.com/cat.png" fmt.Println( webpage + "?image=" + url.QueryEscape(image)) } 
+17
source share

All Articles