Documentation
¶
Overview ¶
Package gofile provides support for file operations.
Index ¶
- Variables
- func Copy(src, dest string) (int64, error)
- func Create(name string) (io.ReadWriteCloser, error)
- func CreateSafe(name string) (io.ReadWriteCloser, error)
- func InitialCapacity(capacity int64) int
- func IsDir(name string) bool
- func IsRegular(name string) bool
- func Mode(file string) os.FileMode
- func PWD() string
- func Stat(file string) (os.FileInfo, error)
- func StatCheck(filename string) (os.FileInfo, error)
- type DIR
- type DataFile
- type DirEntry
- type ErrorLogger
- type File
- type FileInfo
- type FileMode
- type PathError
- type ReadDirFile
- type SortType
- type TextFile
- type TimeZone
Constants ¶
This section is empty.
Variables ¶
var ( EL = errorlogger.EL Err = errorlogger.Err )
Package errorlogger implements error logging to a logrus log by default. It is completely compatible with the standard library 'log' logger API. It provides an efficient and convenient way to log errors with minimal overhead and to temporarily disable or enable logging.
A global EL and Err with default behaviors are supplied that may be aliased if you wish:
EL = errorlogger.EL // implements the ErrorLogger interface Err = errorlogger.Err // trigger function
ErrorLogger is:
type ErrorLogger interface {
Disable()
Enable()
Err(err error) error
SetLoggerFunc(fn func(args ...interface{}))
// SetErrorType allows ErrorLogger to wrap errors in a
// specified custom type. For example, if you want all errors
// returned to be of type *os.PathError
SetErrorType(errType error)
}
var ( ErrBadCount = errors.New("datafile: bad read count") ErrNotRegular = errors.New("datafile: not regular file") )
var SameFile = os.SameFile
SameFile reports whether fi1 and fi2 describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by this package's Stat. It returns false in other cases.
Functions ¶
func Create ¶
func Create(name string) (io.ReadWriteCloser, error)
Create creates or truncates the named file and returns an opened file as io.ReadWriteCloser.
If the file already exists, it is truncated. If the file does not exist, it is created with mode 0644 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
If there is an error, it will be of type *PathError.
func CreateSafe ¶
func CreateSafe(name string) (io.ReadWriteCloser, error)
CreateSafe creates the named file and returns an opened file as io.ReadWriteCloser.
If the file already exists, an error is returned. If the file does not exist, it is created with mode 0644 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
If there is an error, it will be of type *PathError.
func InitialCapacity ¶
InitialCapacity returns the multiple of 'chunk' one more than needed to accomodate the given capacity.
func PWD ¶
func PWD() string
PWD returns a rooted path name corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), PWD may return any one of them.
If an error occurs, the empty string is returned and the error is logged.
Types ¶
type DataFile ¶
func NewDataFile ¶
type DirEntry ¶
type DirEntry interface {
// Name returns the name of the file (or subdirectory) described by the entry.
// This name is only the final element of the path (the base name), not the entire path.
// For example, Name would return "hello.go" not "/home/gopher/hello.go".
Name() string
// IsDir reports whether the entry describes a directory.
IsDir() bool
// Type returns the type bits for the entry.
// The type bits are a subset of the usual FileMode bits, those returned by the FileMode.Type method.
Type() FileMode
// Info returns the FileInfo for the file or subdirectory described by the entry.
// The returned FileInfo may be from the time of the original directory read
// or from the time of the call to Info. If the file has been removed or renamed
// since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist).
// If the entry denotes a symbolic link, Info reports the information about the link itself,
// not the link's target.
Info() (FileInfo, error)
}
A DirEntry is an entry read from a directory (using the ReadDir function or a ReadDirFile's ReadDir method).
type ErrorLogger ¶
type ErrorLogger interface {
// Disable disables logging and sets a no-op function for
// Err() to prevent slowdowns while logging is disabled.
Disable()
// Enable enables logging and restores the Err() logging functionality.
Enable()
// Err logs an error to the provided logger, if it is enabled,
// and returns the error unchanged.
Err(err error) error
// SetLoggerFunc allows setting of the logger function.
// The default is log.Error(), which is compatible with
// the standard library log package and logrus.
SetLoggerFunc(fn func(args ...interface{}))
Wrap(err error, message string) error
}
type File ¶
A File provides access to a single file. The File interface is the minimum implementation required of the file. A file may implement additional interfaces, such as ReadDirFile, ReaderAt, or Seeker, to provide additional or optimized functionality.
Reference: standard library fs.go
type FileInfo ¶
type FileInfo interface {
Name() string // base name of the file
Size() int64 // length in bytes for regular files; system-dependent for others
Mode() FileMode // file mode bits
ModTime() time.Time // modification time
IsDir() bool // abbreviation for Mode().IsDir()
Sys() interface{} // underlying data source (can return nil)
}
A FileInfo describes a file and is returned by Stat and Lstat.
type FileMode ¶
A FileMode represents a file's mode and permission bits. The bits have the same definition on all systems, so that information about files can be moved from one system to another portably. Not all bits apply to all systems. The only required bit is ModeDir for directories.
type PathError ¶
func NewPathError ¶
NewPathError records an error and the operation and file path that caused it.
type PathError struct {
Op string
Path string
Err error
}
type ReadDirFile ¶
type ReadDirFile interface {
File
// ReadDir reads the contents of the directory and returns
// a slice of up to n DirEntry values in directory order.
// Subsequent calls on the same file will yield further DirEntry values.
//
// If n > 0, ReadDir returns at most n DirEntry structures.
// In this case, if ReadDir returns an empty slice, it will return
// a non-nil error explaining why.
// At the end of a directory, the error is io.EOF.
//
// If n <= 0, ReadDir returns all the DirEntry values from the directory
// in a single slice. In this case, if ReadDir succeeds (reads all the way
// to the end of the directory), it returns the slice and a nil error.
// If it encounters an error before the end of the directory,
// ReadDir returns the DirEntry list read until that point and a non-nil error.
ReadDir(n int) ([]DirEntry, error)
}
A ReadDirFile is a directory file whose entries can be read with the ReadDir method. Every directory file should implement this interface. (It is permissible for any file to implement this interface, but if so ReadDir should return an error for non-directories.)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
dir
command
|
|
|
examples/errorlog
command
|
|
|
redlog
command
|
|
|
Package errorlogger implements error logging to a logrus log (or a standard library log) by providing a convenient way to log errors and to temporarily disable/enable logging.
|
Package errorlogger implements error logging to a logrus log (or a standard library log) by providing a convenient way to log errors and to temporarily disable/enable logging. |
|
Package json implements json serialization and deserialization.
|
Package json implements json serialization and deserialization. |
|
Package redlogger implements logging to an io.Writer (default stderr) with text wrapped in ANSI escape codes
|
Package redlogger implements logging to an io.Writer (default stderr) with text wrapped in ANSI escape codes |