There is a word in Russian. It is necessary that the program on golang would produce the same word in the format encoded in the url, i.e. % 23% 45% 67 is a type of this. How to do it?

  • google: // urlencode golang, lazy dormouse - strangeqargo

2 answers 2

package main import ( "net/url" "fmt" ) func main() { fmt.Println(url.QueryEscape("абракадабра")) } 

    If you want to match the version of JS (encodeURIComponent ()) Then:

     import "net/url" func UrlEncoded(str string) (string, error) { u, err := url.Parse(str) if err != nil { return "", err } return u.String(), nil