title: Combine absolute path and relative path to get a new absolute path
body: <p>I'm writing a program in which one of the components must be able to take a path it is given (such as <code>/help/index.html</code>, or <code>/help/</code>) and a relative path based on that location, (such as <code>../otherpage/index.html</code>, or <code>sub/dir/of/help/</code>, or <code>help2.html</code>) and produce the absolute path implied by the relative path. Consider the following directory tree.</p>
  
  <pre><code>/
  index.html
  content.txt
  help/
      help1.html
      help2.html
  </code></pre>
  
  <p>The file <code>index.html</code> contains a link like <code>help/help1.html</code>. The program is passed <code>/</code> or <code>/index.html</code>, and combines it with <code>help/help1.html</code> to get <code>/help/help1.html</code>.</p>
  
  <p>Similarly, the file <code>/help/help1.html</code> has the link <code>../content.txt</code>, from which the program   needs to return <code>/content.txt</code>. Is there a reasonable way to do this?</p>
  
  <p>Thank you. :)</p>
  
  <p><strong>Edit:</strong> Thank you to Stephen Weinberg! For everyone <a href="http://xkcd.com/979/" rel="noreferrer">from the future</a>, here's the code I used.</p>
  
  <pre><code>func join(source, target string) string {
      if path.IsAbs(target) {
          return target
      }
      return path.Join(path.Dir(source), target)
  }
  </code></pre>