homedir

package module
v0.0.0-...-8313989 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2018 License: MIT Imports: 8 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisableCache bool

DisableCache will disable caching of the home directory. Caching is enabled by default.

Functions

func Dir

func Dir() (string, error)

Dir returns the home directory for the executing user.

This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.

func Expand

func Expand(path string) (string, error)

Expand expands the path to include the home directory if the path is prefixed with `~`. If it isn't prefixed with `~`, the path is returned as-is.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL