homedir

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 3 Imported by: 23

README

HomeDir

Build Status Coverage Status Go Report Card GoDoc

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.

Installation

go get -u github.com/atrox/homedir
# or with dep
dep ensure -add github.com/atrox/homedir

Usage

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.

Example

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)
}

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the home directory for the executing user. 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