vanish

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2015 License: MIT Imports: 3 Imported by: 0

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

func Dir(fn func(string)) error

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

func DirIn(dir string, fn func(string)) error

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

func File(fn func(string)) error

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:

func FileIn

func FileIn(dir string, fn func(string)) error

FileIn is like File excepts that it accepts a parent directory as its first argument. If it's empty, the call is equivalent to File.

Types

This section is empty.

Jump to

Keyboard shortcuts

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