Url

Go - On building URL strings

Building URL strings in Go may be accomplished in a couple different ways:

  • url.Parse
  • string concatenation (using +)
  • fmt.Sprintf
  • bytes.Buffer
  • strings.Builder

You may be asking yourself: which one should I use, then? As always, the answer depends. Let us explore why.

URL.Parse

Before we start, a quick refresh on the URL structure:

url

One important fact to be aware is that when building URLs manually, it is easy to forget the percentage-encoding.