file

package
v6.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBackupsLimit = 1024

MaxBackupsLimit is the upper bound on the number of backup files. Any values greater will result in an error.

Variables

This section is empty.

Functions

func ReadOpen added in v6.2.0

func ReadOpen(path string) (*os.File, error)

ReadOpen opens a file for reading only

func SafeFileRotate

func SafeFileRotate(path, tempfile string) error

SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile

Types

type FileInfo

type FileInfo interface {
	os.FileInfo
	UID() (int, error) // UID of the file owner. Returns an error on non-POSIX file systems.
	GID() (int, error) // GID of the file owner. Returns an error on non-POSIX file systems.
}

A FileInfo describes a file and is returned by Stat and Lstat.

func Lstat

func Lstat(name string) (FileInfo, error)

Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.

func Stat

func Stat(name string) (FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

type Rotator added in v6.2.0

type Rotator struct {
	// contains filtered or unexported fields
}

Rotator is a io.WriteCloser that automatically rotates the file it is writing to when it reaches a maximum size. It also purges the oldest rotated files when the maximum number of backups is reached.

func NewFileRotator added in v6.2.0

func NewFileRotator(filename string, options ...RotatorOption) (*Rotator, error)

NewFileRotator returns a new Rotator.

func (*Rotator) Close added in v6.2.0

func (r *Rotator) Close() error

Close closes the currently open file.

func (*Rotator) Rotate added in v6.2.0

func (r *Rotator) Rotate() error

Rotate triggers a file rotation.

func (*Rotator) Sync added in v6.2.0

func (r *Rotator) Sync() error

Sync commits the current contents of the file to stable storage. Typically, this means flushing the file system's in-memory copy of recently written data to disk.

func (*Rotator) Write added in v6.2.0

func (r *Rotator) Write(data []byte) (int, error)

Write writes the given bytes to the file. This implements io.Writer. If the write would trigger a rotation the rotation is done before writing to avoid going over the max size. Write is safe for concurrent use.

type RotatorOption added in v6.2.0

type RotatorOption func(r *Rotator)

RotatorOption is a configuration option for Rotator.

func MaxBackups added in v6.2.0

func MaxBackups(n uint) RotatorOption

MaxBackups configures the maximum number of backup files to save (not counting the active file). The upper limit is 1024 on this value is. The default is 7.

func MaxSizeBytes added in v6.2.0

func MaxSizeBytes(n uint) RotatorOption

MaxSizeBytes configures the maximum number of bytes that a file should contain before being rotated. The default is 10 MiB.

func Permissions added in v6.2.0

func Permissions(m os.FileMode) RotatorOption

Permissions configures the file permissions to use for the file that the Rotator creates. The default is 0600.

type StateOS added in v6.2.0

type StateOS struct {
	Inode  uint64 `json:"inode,"`
	Device uint64 `json:"device,"`
}

func GetOSState added in v6.2.0

func GetOSState(info os.FileInfo) StateOS

GetOSState returns the FileStateOS for non windows systems

func (StateOS) IsSame added in v6.2.0

func (fs StateOS) IsSame(state StateOS) bool

IsSame file checks if the files are identical

func (StateOS) String added in v6.2.0

func (fs StateOS) String() string

Jump to

Keyboard shortcuts

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