Golang net/url.QueryEscape() function examples

package net/url

Golang net/url.QueryEscape() function usage examples

Example 1 :

 var postStr string = paypal_url + "&cmd=_notify-validate&"

  for k, v := range r.Form {
 fmt.Println("key :", k)
 fmt.Println("value :", strings.Join(v, ""))

 // NOTE : Store the IPN data k,v into a slice. It will be useful for database entry later.

 postStr = postStr + k + "=" + url.QueryEscape(strings.Join(v, "")) + "&"
  }

Example 2 :

 func TagSearch(tag string) string {
 return fmt.Sprintf("https://example.com/search?q=%s", url.QueryEscape(tag))
 }

References :

http://golang.org/pkg/net/url/#QueryEscape

https://www.socketloop.com/tutorials/golang-interfacing-with-paypal-s-ipn-instant-payment-notification-example

Advertisement