Skip to content

Instantly share code, notes, and snippets.

@teocci
Created April 6, 2022 08:54
Show Gist options
  • Save teocci/4af946fb41234e71ed82cd4a2677853a to your computer and use it in GitHub Desktop.
Save teocci/4af946fb41234e71ed82cd4a2677853a to your computer and use it in GitHub Desktop.
package main
import (
"path"
"path/filepath"
"runtime"
)
var (
// Current working directory
cwdPath, _ = os.Getwd()
// from Executable Directory
x, _ = os.Executable()
executablePath = filepath.Dir(x)
// Relative on runtime DIR:
_, b, _, _ = runtime.Caller(0)
relativePath = filepath.Dir(b)
)
func DirPaths() {
fmt.Println("CWD PATH:", cwdPath)
fmt.Println("Executable PATH:", filepath.Dir(executablePath))
fmt.Println("Relative PATH:", relativePath)
d := path.Join(path.Dir(b))
fmt.Println("Relative-d PATH:", filepath.Dir(d))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment