title: How can I open files relative to my GOPATH?
body: <p>I'm using <code>io/ioutil</code> to read a small text file:</p>
  
  <pre><code>fileBytes, err := ioutil.ReadFile("/absolute/path/to/file.txt")
  </code></pre>
  
  <p>And that works fine, but this isn't exactly portable. In my case, the files I want to open are in my GOPATH, for example:</p>
  
  <pre><code>/Users/matt/Dev/go/src/github.com/mholt/mypackage/data/file.txt
  </code></pre>
  
  <p>Since the <code>data</code> folder rides right alongside the source code, I'd love to just specify the relative path:</p>
  
  <pre><code>data/file.txt
  </code></pre>
  
  <p>But then I get this error:</p>
  
  <blockquote>
    <p>panic: open data/file.txt: no such file or directory</p>
  </blockquote>
  
  <p>How can I open files using their relative path, especially if they live alongside my Go code?</p>
  
  <p><em>(<strong>Note that my question is specifically about opening files relative to the GOPATH.</strong> Opening files using any relative path in Go is as easy as giving the relative path instead of an absolute path; files are opened relative to the compiled binary's working directory. In my case, I want to open files relative to where the binary was compiled. In hindsight, this is a bad design decision.)</em></p>