dirs

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 6 Imported by: 109

Documentation

Overview

Package dirs implements utility functions for creating, getting information on and removing directories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetwdEvalSymLinks() (string, error)

GetwdEvalSymLinks returns the working directory of the current process using os.GetWd(). Returns the path with all symbolic links resolved (equivalent to 'pwd -P'). Returns an error if os.Getwd or filepath.EvalSymlinks returns an error.

func GoRoot

func GoRoot() (string, error)

GoRoot returns the value for GOROOT for the current system. Similar to runtime.GOROOT(), but if the GOROOT environment variable is not set, falls back on the value provided by the output of running "go env GOROOT" rather than using sys.DefaultGoroot. This approach is more portable in situations where the binary is being run in an environment that is different from the one in which it is compiled.

func MustGetwdEvalSymLinks() string

MustGetwdEvalSymLinks returns the result of GetwdEvalSymLinks. If GetwdEvalSymLinks returns an error, panics.

func RemoveAllFunc

func RemoveAllFunc(path string) func()

RemoveAllFunc returns a function that calls os.RemoveAll on the specified path and prints any error that is encountered using fmt.Printf. Useful as a defer function to clean up directories created in tests.

func SetGoEnvVariables

func SetGoEnvVariables() error

SetGoEnvVariables sets the values of the GOPATH and GOROOT environment variables to be the correct values with all symbolic links evaluated. The GOPATH to resolve is determined by using the original value of the GOPATH environment variable, while the GOROOT to resolve is determined using the GoRoot() function.

func SetwdWithRestorer

func SetwdWithRestorer(dir string) (func(), error)

SetwdWithRestorer sets the working directory to be the specified directory and returns a function that restores the working directory to the value before it was changed. The returned function is suitable for use in a defer call.

func TempDir

func TempDir(dir, prefix string) (string, func(), error)

TempDir creates a directory using ioutil.TempDir. If the ioutil.TempDir call is successful, returns its result and a function that removes the directory. The returned function is suitable for use in a defer call.

Types

This section is empty.

Jump to

Keyboard shortcuts

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