github.com/haraldrudell/parl@v0.4.176/pos/dir.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pos 7 8 import ( 9 "os" 10 "path/filepath" 11 12 "github.com/haraldrudell/parl/perrors" 13 "github.com/haraldrudell/parl/pfs" 14 ) 15 16 // ParentDir gets absolute path of executable parent directory 17 func ParentDir() (dir string) { 18 return filepath.Dir(ExecDir()) 19 } 20 21 // ExecDir gets abolute path to directory where executable is located 22 func ExecDir() (dir string) { 23 var executable string 24 var err error 25 if executable, err = os.Executable(); err != nil { 26 panic(perrors.Errorf("os.Executable: %w", err)) 27 } 28 dir = pfs.Abs(filepath.Dir(executable)) 29 return 30 }