Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultFileMode is the file mode used by NewFileWriter DefaultFileMode os.FileMode = 0644 // DefaultOpenFlag is the os.OpenFile flag used by NewFileWriter DefaultOpenFlag = os.O_CREATE | os.O_WRONLY | os.O_APPEND // DefaultTempFile is the os.CreateTemp pattern used by NewFileWriter DefaultTempFile = "filewriter-*.tmp" )
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder interface { // SetFile specifies the file path to use SetFile(file string) Builder // UseTemp specifies the pattern to use with os.CreateTemp. If the pattern // includes a unix directory separator, the `pattern` argument is the base // name and the rest is used as the `dir` argument UseTemp(pattern string) Builder // SetMode specifies the file permissions to use when creating files SetMode(mode os.FileMode) Builder // Make initializes the settings configured with other Builder methods and // returns the FileWriter instance Make() (writer FileWriter, err error) }
Builder is the buildable interface for constructing new FileWriter instances
type FileWriter ¶
type FileWriter interface { // File returns the underlying file name File() (file string) // Mode returns the file permissions used when creating files Mode() (mode os.FileMode) // Remove deletes the underlying file Remove() (err error) // Write opens the log file, writes the data given and returns the number // of bytes written and the error state after closing the open file handle Write(p []byte) (n int, err error) // WriteString is a convenience wrapper around Write WriteString(s string) (n int, err error) // Close flags this FileWriter as being closed, blocking any further Write // or WriteString operations; ReadFile and WalkFile can still be used // until Remove is called Close() (err error) // ReadFile returns the entire file contents ReadFile() (data []byte, err error) // WalkFile opens the output file and scans one line at a time, calling the // given `fn` for each. If the `fn` returns true, the walk stops. WalkFile // returns true if the walk was stopped. WalkFile will panic on any os.Open // error that is not os.ErrNotExist WalkFile(fn func(line string) (stop bool)) (stopped bool) }
FileWriter is an io.WriteCloser that does not keep file handles open any longer than necessary and provides additional methods for interacting with the underlying file. All operations are safe for concurrent calls
Click to show internal directories.
Click to hide internal directories.