title: How to choose URL encoding standard in Go?
body: <p>I have a Go client that is communicating with a server that follows <a href="https://www.rfc-editor.org/rfc/rfc1738" rel="nofollow noreferrer">RFC 1738</a> URL encoding rules. RFC 1738 has since been updated (replaced) by <a href="https://www.rfc-editor.org/rfc/rfc3986" rel="nofollow noreferrer">RFC 3986</a>, which is what Go seems to be using, at least in v1.17.7.</p>
  <pre><code>s := &quot;blue+~light blue&quot;
  s = url.QueryEscape(s)
  fmt.Println(s) // blue%2B~light+blue
  </code></pre>
  <p>In RFC 1738, <code>~</code> is a reserved (&quot;unsafe&quot;) character and should be encoded as <code>%7E</code>, whereas in RFC 3986 it's not necessary to encode <code>~</code>. This is just one difference between the two RFCs, there are likely others that I've not looked into yet, which is why a naive approach of replacing <code>~</code> with <code>%7E</code> isn't the path I want to go down.</p>
  <p>Can I make Go create an &quot;RFC 1738 compatible&quot; encoded URL? If not, are there third-party libraries that can do this, perhaps by accepting an RFC number parameter? <code>time</code> already does this:</p>
  <pre><code>t.Format(time.RFC822)
  t.Format(time.RFC850)
  t.Format(time.RFC1123)
  t.Format(time.RFC3339)
  </code></pre>