Documentation ¶
Overview ¶
Package scrubber provides an easy way to clean up old files in a directory.
Index ¶
- type Filesystem
- type OSFilesystem
- func (fs OSFilesystem) Create(name string) (*os.File, error)
- func (fs OSFilesystem) Ext(file os.FileInfo) string
- func (fs OSFilesystem) FullPath(file os.FileInfo, dir string) string
- func (fs OSFilesystem) ListFiles(path string) ([]os.FileInfo, error)
- func (fs OSFilesystem) Name(file os.FileInfo) string
- func (fs OSFilesystem) Open(name string) (*os.File, error)
- func (fs OSFilesystem) Remove(path string) error
- func (fs OSFilesystem) Stat(name string) (os.FileInfo, error)
- type Scrubber
- type Strategy
- type StrategyAction
- type StrategyConfig
- type StrategyType
- type TomlConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filesystem ¶
type Filesystem interface { Name(file os.FileInfo) string FullPath(file os.FileInfo, dir string) string Remove(path string) error Open(name string) (*os.File, error) Create(name string) (*os.File, error) Stat(name string) (os.FileInfo, error) ListFiles(path string) ([]os.FileInfo, error) Ext(file os.FileInfo) string }
Filesystem represents the minimal fs implementation we expect.
type OSFilesystem ¶
type OSFilesystem struct { }
OSFilesystem proxies calls to the underlying os and file library calls.
func (OSFilesystem) Create ¶
func (fs OSFilesystem) Create(name string) (*os.File, error)
Create creates a file on the filesystem.
func (OSFilesystem) Ext ¶
func (fs OSFilesystem) Ext(file os.FileInfo) string
Ext returns a file's extension.
func (OSFilesystem) FullPath ¶
func (fs OSFilesystem) FullPath(file os.FileInfo, dir string) string
FullPath combines a file's name and it's path to a full path string.
func (OSFilesystem) ListFiles ¶
func (fs OSFilesystem) ListFiles(path string) ([]os.FileInfo, error)
ListFiles returns a os.FileInfo for every file in a directory.
func (OSFilesystem) Name ¶
func (fs OSFilesystem) Name(file os.FileInfo) string
Name returns the name of a file.
func (OSFilesystem) Open ¶
func (fs OSFilesystem) Open(name string) (*os.File, error)
Open reads a file from the filesystem.
func (OSFilesystem) Remove ¶
func (fs OSFilesystem) Remove(path string) error
Remove deletes a file from the filesystem.
type Scrubber ¶
type Scrubber struct {
// contains filtered or unexported fields
}
Scrubber holds the configuration and a filesystem handle.
func New ¶
func New(c *TomlConfig, fs Filesystem, log logger, pretend bool) *Scrubber
New returns a new instance of Scrubber.
type Strategy ¶
type Strategy struct {
// contains filtered or unexported fields
}
Strategy represents an action to take with files.
type StrategyAction ¶
type StrategyAction string
StrategyAction represents the action that should be taken for matching files.
const ( // ActionTypeDelete is used to delete old files. ActionTypeDelete StrategyAction = "delete" // ActionTypeZip is used to zip old files. ActionTypeZip StrategyAction = "zip" )
type StrategyConfig ¶
type StrategyConfig struct { Type StrategyType Action StrategyAction Limit string }
StrategyConfig holds all specified strategies for a single Directory.
type StrategyType ¶
type StrategyType string
StrategyType defines how to decide what files should be cleaned up.
const ( // StrategyTypeAge makes files past a certain age to be deleted. StrategyTypeAge StrategyType = "age" // StrategyTypeSize makes files past a certain size to be deleted. StrategyTypeSize StrategyType = "size" )
type TomlConfig ¶
type TomlConfig struct { Title string Directories []directory `toml:"directory"` }
TomlConfig holds the complete structure of the scrubber config file.