io

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package io provides atomic file I/O and rotating file writer utilities.

Index

Constants

View Source
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
)
View Source
const ChecksumSize = 8

ChecksumSize is the length (in bytes) of the CRC64 checksum header

Variables

This section is empty.

Functions

func AtomicallySaveToFile

func AtomicallySaveToFile(fileName string, data []byte) (err error)

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

func CleanupFolders(dirs []string, ignoreFiles ...string) error

CleanupFolders ensures that each directory in dirs exists and removes all entries except in ignoreFiles

func LoadFromFile

func LoadFromFile(path string) (data []byte, err error)

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

func (*RotatingFileWriter) Write

func (r *RotatingFileWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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