title: resolve symlinks in Go
body: <p>How can I resolve symlinks in Go?</p>
  
  <p>Currently I call <code>readlink -f</code> but I want something more idiomatic.</p>
  
  <pre><code>package main
  
  import (
      "os/exec"
      "fmt"
  )
  
  func resolve(p string) string {
      cmd := exec.Command("readlink", "-f", p)
      out, _ := cmd.Output()
  
      return (string(out))
  }
  
  func main() {
      fmt.Printf(resolve("/initrd.img"))
  }
  </code></pre>