Documentation
¶
Overview ¶
Package temp_dir is a package that provides the basic functionality of creating a temporary directory and deleting the directory and all of its files when it is done. It's typically used in testing scenarios
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTempDirPrefix string = "td_" DefaultDirPermissions os.FileMode = 0774 /*group and user (read+write+execute), other (read). execute for directories allows directory listing (listing entries in directory)*/ DefaultFilePermissions os.FileMode = 0664 /*group and user (read+write), other (read)*/ )
Functions ¶
This section is empty.
Types ¶
type PathErrorPrinter ¶ added in v0.1.3
type PathMessagePrinter ¶ added in v0.1.3
type PathMessagePrinter func(path, message string)
type TempDir ¶
type TempDir interface { /*DirPath the temp dir path (absolute path)*/ DirPath() string /*GetRandomSubPath generates and returns a valid random (absolute) path where the parent is the temp dir. The provided prefix will be used in the generation of the path name. Generated path name is like "<prefix>1234"*/ GetRandomSubPath(prefix string) string /*CreateSubFile creates a file in the temp dir path, the populate the file with the provided fileData if any. If filename was empty, then filenamePrefix will be used to generate a random filename. returns the full path of the created file */ CreateSubFile(filename string, filenamePrefix string, fileData []byte) (string, error) io.Closer }
TempDir encloses the functionality that can be done on a temp dir. Closing the temp dir deletes it and all of its content recursively
func CreateTempDir ¶
func CreateTempDir( parentPath string, tempDirPrefix string, logAction func(path, message string), logError func(path string, err error) (panic bool), ) (TempDir, error)
CreateTempDir creates and returns a TempDir.
parentPath: is the directory path where this temp dir will be created in
tempDirPrefix: if it is not empty then it will be used as a prefix for the name of the temp dir (like <prefix>_1234)
logAction: is a function that is used to log when path (dir or file) creation or deletion have happened (default is some pretty printer)
logError: is a function that will be used to log when an error happens, the error will still be propagated. if the return value (panic bool) is true, then application will panic after using this function (except when used in defer/Close scenario, then no panic). (default value will pretty print then return true)