osext.go 851 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Extensions to the standard "os" package.
  5. package osext
  6. import "path/filepath"
  7. // Executable returns an absolute path that can be used to
  8. // re-invoke the current program.
  9. // It may not be valid after the current program exits.
  10. func Executable() (string, error) {
  11. p, err := executable()
  12. return filepath.Clean(p), err
  13. }
  14. // Returns same path as Executable, returns just the folder
  15. // path. Excludes the executable name.
  16. func ExecutableFolder() (string, error) {
  17. p, err := Executable()
  18. if err != nil {
  19. return "", err
  20. }
  21. folder, _ := filepath.Split(p)
  22. return folder, nil
  23. }
  24. // Depricated. Same as Executable().
  25. func GetExePath() (exePath string, err error) {
  26. return Executable()
  27. }