Documentation
¶
Index ¶
- Variables
- func CanUpdate(v interface{}) bool
- func EnvMap() map[string]string
- func Environ() []string
- func Example()
- func Expand(path string) (string, error)
- func GetHomeDir() (string, error)
- func Getenv(envVarName string, defaultValue string) (retval string)
- func MustSet(ptr interface{})
- func Reset()
- func Set(ptr interface{}) error
- func Setenv(key, value string) error
- func Shell(commands ...string) (string, string, error)
- func ShellPool(args ...string) (string, string, error)
- type Dir
- type GetSetter
- type Setter
Constants ¶
This section is empty.
Variables ¶
var DisableCache bool
/ ------------------------------------------------------ old version DisableCache will disable caching of the home directory. Caching is enabled by default.
var (
HOME = NewHome
)
Functions ¶
func CanUpdate ¶
func CanUpdate(v interface{}) bool
CanUpdate returns true when the given value is an initial value of its type
func EnvMap ¶
EnvMap returns a mapping of string keys to string values representing the environment, in the form "m[key] == value", e.g.
home := m["HOME"] fmt.Println(home) // /Users/skeptycal/
func Environ ¶
func Environ() []string
Environ returns a copy of strings representing the environment, in the form "key=value".
func Expand ¶
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.
func GetHomeDir ¶
GetHomeDir 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 Getenv ¶
Getenv returns the value of the string while replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by defaultValue.
d := Getenv("${HOME}/.config") fmt.Println(d) // /Users/skeptycal/.config
func MustSet ¶
func MustSet(ptr interface{})
MustSet function is a wrapper of Set function It will call Set and panic if err not equals nil.
func Reset ¶
func Reset()
Reset clears the cache, forcing the next call to Dir to re-detect the home directory. This generally never has to be called, but can be useful in tests if you're modifying the home directory via the HOME env var or something.
func Set ¶
func Set(ptr interface{}) error
Set initializes members in a struct referenced by a pointer. Maps and slices are initialized by `make` and other primitive types are set with default values. `ptr` should be a struct pointer
func Setenv ¶
Setenv sets the value of the environment variable named by the key. It returns an error, if any.
func Shell ¶
ShBuffered executes the named shell command and returns stdout, stderr, and any error that occurred.
The buffers for the command outputs are standard bytes.Buffers and may not be performant for multiple repeated commands. See ShellPool.
The default timeout is 10 seconds.