title: Expand tilde to home directory
body: <p>I have a program that accepts a destination folder where files will be created. My program should be able to handle absolute paths as well as relative paths. My problem is that I don't know how to expand <code>~</code> to the home directory.</p>
  
  <p>My function to expand the destination looks like this. If the path given is absolute it does nothing otherwise it joins the relative path with the current working directory.</p>
  
  <pre><code>import "path"
  import "os"
  
  // var destination *String is the user input
  
  func expandPath() {
          if path.IsAbs(*destination) {
                  return
          }
          cwd, err := os.Getwd()
          checkError(err)
          *destination = path.Join(cwd, *destination)
  }
  </code></pre>
  
  <p>Since <a href="http://godoc.org/path#Join"><code>path.Join</code></a> doesn't expand <code>~</code> it doesn't work if the user passes something like <code>~/Downloads</code> as the destination.</p>
  
  <p>How should I solve this in a cross platform way?</p>