Basic project structure
This commit is contained in:
23
util/env.go
Normal file
23
util/env.go
Normal file
@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"os/user"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ResolveTilde(path string) string {
|
||||
usr, _ := user.Current()
|
||||
dir := usr.HomeDir
|
||||
|
||||
if path == "~" {
|
||||
// In case of "~", which won't be caught by the "else if"
|
||||
path = dir
|
||||
} else if strings.HasPrefix(path, "~/") {
|
||||
// Use strings.HasPrefix so we don't match paths like
|
||||
// "/something/~/something/"
|
||||
path = filepath.Join(dir, path[2:])
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
Reference in New Issue
Block a user