Last active
May 30, 2017 06:04
-
-
Save ymgyt/7642d43690d803bd0e650416526f5f6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func absPathify(inPath string) string { | |
if strings.HasPrefix(inPath, "$HOME") { | |
inPath = userHomeDir() + inPath[5:] | |
} | |
if strings.HasPrefix(inPath, "$") { | |
end := strings.Index(inPath, string(os.PathSeparator)) | |
inPath = os.Getenv(inPath[1:end]) + inPath[end:] | |
} | |
if filepath.IsAbs(inPath) { | |
return filepath.Clean(inPath) | |
} | |
p, err := filepath.Abs(inPath) | |
if err == nil { | |
return filepath.Clean(p) | |
} | |
jww.ERROR.Println("Couldn't discover absolute path") | |
jww.ERROR.Println(err) | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment