A go package for detecting and expanding the user's home directory without cgo.
Clone or download
Pull request Compare This branch is 10 commits ahead, 4 commits behind mitchellh:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.appveyor.yml
.travis.yml
LICENSE
README.md
homedir.go
homedir_darwin.go
homedir_plan9.go
homedir_test.go
homedir_unix.go
homedir_windows.go

README.md

homedir

Linux/OSX Build Status Windows Build Status Codecov Go Report Card Go docs

A Go library for getting the user's home directory without cgo allowing for cross compilation.

This is a tracking fork of mitchellh/go-homedir that is kept up-to-date with changes upstream. The original uses runtime checks to select the logic used. This fork uses go build tags rather than runtime checks. This was suggested in a two PRs (#13, #10) but wasn't a fit for the specific purpose that the original had been developed for, leading to this fork.

Usage

import "4d63.com/homedir"

// Call `homedir.Dir()` to get the home directory of the current user.
homePath := homedir.Dir()

// Call `homedir.Expand()` to expand the `~` in a path to the home directory of the current user.
absPath := homedir.Expand("~/a/path/in/the/home")

Why not use the built in os/user?

The built-in os/user package requires cgo on Darwin (Mac) systems. This means that any Go code that uses that package cannot cross compile. Much of the time the use for os/user is only to retrieve the home directory, which we can do for the current user without cgo. This library does that, enabling cross-compilation.