Documentation
¶
Overview ¶
Package io provides atomic file I/O and rotating file writer utilities.
Index ¶
Constants ¶
const ( // DefaultMaxFileSize is the default maximum file size before rotation (10MB) DefaultMaxFileSize = 10 * 1024 * 1024 // MaxRotatedFiles is the maximum number of rotated files to keep (current + 5 rotated = 60MB total) MaxRotatedFiles = 5 )
const ChecksumSize = 8
ChecksumSize is the length (in bytes) of the CRC64 checksum header
Variables ¶
This section is empty.
Functions ¶
func AtomicallySaveToFile ¶
AtomicallySaveToFile saves given data to the given file atomically Appends a CRC64 checksum to the data before writing File is either fully updated or not updated at all -> done by writing to a temporary file and renaming after
func CleanupFolders ¶
CleanupFolders ensures that each directory in dirs exists and removes all entries except in ignoreFiles
func LoadFromFile ¶
LoadFromFile loads data from the given file and verifies the checksum Returns data w/o checksum
Types ¶
type RotatingFileWriter ¶
type RotatingFileWriter struct {
// contains filtered or unexported fields
}
RotatingFileWriter is an io.Writer that rotates files when they exceed a size limit
func NewRotatingFileWriter ¶
func NewRotatingFileWriter(filePath string, maxSize int64) (*RotatingFileWriter, error)
NewRotatingFileWriter creates a new RotatingFileWriter filePath: path to the log file (e.g., "/proxy/logs/proxy-debug.log" or "./logs/gateway-debug.log") maxSize: maximum file size in bytes before rotation (default: 10MB)
func (*RotatingFileWriter) Close ¶
func (r *RotatingFileWriter) Close() error
Close implements io.Closer