title: Is there a urlencode() function in golang?
body: <p>Many languages, such as JavaScript and PHP, have a <code>urlencode()</code> function which one can use to encode the content of a query string parameter.</p>
  
  <pre><code>"example.com?value=" + urlencode("weird string &amp; number: 123")
  </code></pre>
  
  <p>This ensures that the <code>&amp;</code>, <code>%</code>, spaces, etc. get encoded so your URL remains valid.</p>
  
  <p>I see that golang offers a URL package and it has an <a href="https://golang.org/pkg/net/url/#Values.Encode" rel="noreferrer">Encode() function</a> for <em>query string values</em>. This works great, but in my situation, it would require me to parse the URL and I would prefer to not do that.</p>
  
  <p>My URLs are declared by the client and not changing the order and potential duplicated parameters (which is a legal thing in a URL) could be affected. So I use a <code>Replace()</code> like so:</p>
  
  <pre><code>func tweak(url string) string {
    url.Replace("@VALUE@", new_value, -1)
    return url
  }
  </code></pre>
  
  <p>The <code>@VALUE@</code> is expected to be used as the value of a query string parameter as in:</p>
  
  <pre><code>example.com?username=@VALUE@
  </code></pre>
  
  <p>So, what I'd like to do is this:</p>
  
  <pre><code>  url.Replace("@VALUE@", urlencode(new_value), -1)
  </code></pre>
  
  <p>Is there such a function readily accessible in Golang?</p>