Documentation ¶
Overview ¶
Package vanish provides a minimal Go library to use temporary files and directories.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir creates a temporary directory and passes its name to the function passed as an argument. The directory is deleted when the function returns.
Example ¶
Dir(func(name string) { // Dir works like File, but it creates a directory instead. Use it as // you wish, it’ll be deleted at the end of this function. })
Output:
func DirIn ¶
DirIn is like Dir except that it accepts a parent directory as its first argument. If it’s empty, the call is equivalent to Dir.
func Env ¶
func Env(fn func()) error
Env ensures the environment stays the same when the function passed as an argument is executed.
Example ¶
os.Setenv("VANISH", "xyz") Env(func() { // Env saves the environment before calling this function, ensuring // it’s restored as it was at its end. os.Setenv("VANISH", "foo") fmt.Printf("VANISH (1) = %s\n", os.Getenv("VANISH")) }) fmt.Printf("VANISH (2) = %s\n", os.Getenv("VANISH"))
Output: VANISH (1) = foo VANISH (2) = xyz
func File ¶
File creates a temporary file and passes its name to the function passed as an argument. The file is deleted when the function returns.
Example ¶
File(func(name string) { // 'name' is the name of a temporary file that’ll be deleted at the end // of the function. You can thus use it for your tests without worrying // about it })
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.