User homedir globbing for Go.
go get -u github.com/hazaelsan/userglob
import "github.com/hazaelsan/userglob"
To perform globbing for an arbitrary user user
:
import "github.com/hazaelsan/userglob"
if expanded, err := userglob.Glob("~user/some/path"); err == nil {
fmt.Printf("Expanded path is %v", expanded)
}
The following two are similar, but using userglob
is more resilient:
// $HOME may be manipulated or even missing
expanded := path.Join(os.Getenv("HOME"), "/some/path")
if expanded, err := userglob.Glob("~/some/path"); err == nil {
fmt.Printf("Expanded path is %v", path)
}