Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT: As of Go 1.8 (Released February 2017) the recommended way of doing this is with <a href="https://tip.golang.org/pkg/os/#Executable" rel="noreferrer"><code>os.Executable</code></a>:</p> <blockquote> <p><code>func Executable() (string, error)</code></p> <p>Executable returns the path name for the executable that started the current process. There is no guarantee that the path is still pointing to the correct executable. If a symlink was used to start the process, depending on the operating system, the result might be the symlink or the path it pointed to. If a stable result is needed, path/filepath.EvalSymlinks might help.</p> </blockquote> <p>To get just the directory of the executable you can use <a href="https://golang.org/pkg/path/filepath/#Dir" rel="noreferrer"><code>path/filepath.Dir</code></a>.</p> <p><a href="https://play.golang.org/p/_aolLr7uEH" rel="noreferrer">Example</a>:</p> <pre><code>package main import ( "fmt" "os" "path/filepath" ) func main() { ex, err := os.Executable() if err != nil { panic(err) } exPath := filepath.Dir(ex) fmt.Println(exPath) } </code></pre> <hr> <p>OLD ANSWER:</p> <p>You should be able to use <a href="http://golang.org/pkg/os/#Getwd" rel="noreferrer"><code>os.Getwd</code></a></p> <pre><code>func Getwd() (pwd string, err error) </code></pre> <blockquote> <p>Getwd returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), Getwd may return any one of them. </p> </blockquote> <p>For example:</p> <pre><code>package main import ( "fmt" "os" ) func main() { pwd, err := os.Getwd() if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println(pwd) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload