This library is based on and fully compatible with mitchellh/go-homedir but uses
os/user
because since go 1.9 there is no longer cgo compilation required.
go get -u github.com/atrox/homedir
# or with dep
dep ensure -add github.com/atrox/homedir
Usage is incredibly simple, just call homedir.Dir()
to get the home directory
for a user, and homedir.Expand(path string)
to expand the ~
in a path to the home
directory.
package main
import (
"fmt"
"github.com/atrox/homedir"
)
func main() {
dir, err := homedir.Dir()
if err != nil {
panic(err)
}
fmt.Printf("'%s' is your users home directory\n", dir)
path, err := homedir.Expand("~/.config")
if err != nil {
panic(err)
}
fmt.Printf("'%s' is the expanded path to the .config directory\n", path)
}
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features