Documentation
¶
Index ¶
- func AddListener(path string, l Listener)
- func CheckFileExists(filePath string) bool
- func CompressFile(fileIn string, fileOut string) error
- func Contains[T comparable](items []T, item T) bool
- func CopyDir(src string, dst string) (err error)
- func CopyFile(src, dst string) (err error)
- func DiskUsage(dirpath string) float64
- func FsWatcherShutdown()
- func GetFilecount(path string) int
- func GetFilesize(filePath string) int64
- func Max[T cmp.Ordered](a, b T) T
- func Mean(input []float64) (float64, error)
- func Median(input []float64) (median float64, err error)
- func Min[T cmp.Ordered](a, b T) T
- func UncompressFile(fileIn string, fileOut string) error
- type Float
- type FloatArray
- type Listener
- type Selector
- type SelectorElement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddListener ¶ added in v0.3.0
AddListener registers a new file system watcher for the specified path. The watcher is initialized on the first call to AddListener. The listener will be notified of file system events matching its EventMatch criteria.
func CheckFileExists ¶
CheckFileExists checks if a file or directory exists at the given path. Returns true if the file exists, false otherwise.
func CompressFile ¶
CompressFile compresses a file using gzip compression. It reads the input file (fileIn), creates a gzip-compressed output file (fileOut), and removes the original file upon successful compression. Returns an error if any operation fails.
func Contains ¶
func Contains[T comparable](items []T, item T) bool
Contains checks if an item exists in a slice of comparable items. It is a generic wrapper around slices.Contains that works with any comparable type T.
func CopyDir ¶
CopyDir recursively copies a directory from src to dst, preserving file modes. It creates the destination directory with the same permissions as the source, and recursively copies all files and subdirectories. Symbolic links are skipped during the copy operation. Returns an error if the source is not a directory, if the destination already exists, or if any file operation fails.
func CopyFile ¶
CopyFile copies a file from src to dst, preserving the file mode. It creates the destination file, copies the content, syncs to disk, and sets the same permissions as the source file. Returns an error if any operation fails.
func DiskUsage ¶
DiskUsage calculates the total disk usage of a directory in megabytes (MB). It sums up the sizes of all files in the specified directory (non-recursive) and returns the result in MB (multiplied by 1e-6). Returns 0 if the directory cannot be opened or read.
func FsWatcherShutdown ¶ added in v0.3.0
func FsWatcherShutdown()
FsWatcherShutdown closes the file system watcher. This should be called during application shutdown to clean up resources.
func GetFilecount ¶
GetFilecount returns the number of entries (files and directories) in a directory. Returns 0 if the directory cannot be read.
func GetFilesize ¶
GetFilesize returns the size of a file in bytes. Returns 0 if the file cannot be accessed or does not exist.
func Mean ¶
Mean calculates the arithmetic mean (average) of a float64 slice. Returns NaN and an error if the input slice is empty.
func Median ¶
Median calculates the median value of a float64 slice. For even-length slices, it returns the mean of the two middle values. For odd-length slices, it returns the middle value. Returns NaN and an error if the input slice is empty.
func UncompressFile ¶
UncompressFile decompresses a gzip-compressed file. It reads the gzip-compressed input file (fileIn), creates an uncompressed output file (fileOut), and removes the compressed file upon successful decompression. Returns an error if any operation fails.
Types ¶
type Float ¶ added in v0.5.0
type Float float64
Float is a custom float64 type that properly handles NaN values in JSON. Go's JSON encoder for floats does not support NaN (https://github.com/golang/go/issues/3480). This program uses NaN as a signal for missing data. For the HTTP JSON API to be able to handle NaN values, Float implements encoding/json.Marshaler and encoding/json.Unmarshaler, converting NaN to/from JSON null.
func ConvertToFloat ¶ added in v0.5.0
ConvertToFloat converts a float64 to a Float. It treats -1.0 as a special value and converts it to NaN.
func (Float) IsNaN ¶ added in v0.5.0
IsNaN returns true if this Float value represents NaN (Not-a-Number).
func (Float) MarshalJSON ¶ added in v0.5.0
MarshalJSON implements json.Marshaler. It converts NaN values to JSON null, and normal float values to JSON numbers with 3 decimal places.
func (*Float) UnmarshalJSON ¶ added in v0.5.0
UnmarshalJSON implements json.Unmarshaler. It converts JSON null to NaN, and normal JSON numbers to Float values.
type FloatArray ¶ added in v0.5.0
type FloatArray []Float
FloatArray is a slice of Float values with optimized JSON marshaling. It can be marshaled to JSON with fewer allocations than []Float.
func (FloatArray) MarshalJSON ¶ added in v0.5.0
func (fa FloatArray) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler for FloatArray. It efficiently marshals a slice of Float values, converting NaN to null.
type Listener ¶ added in v0.3.0
Listener is an interface for file system event callbacks. Implementations should define what events to match and how to respond to them.
type Selector ¶ added in v0.5.0
type Selector []SelectorElement
Selector is a slice of SelectorElements used for matching and filtering.
type SelectorElement ¶ added in v0.5.0
SelectorElement represents a selector that can be either a single string, an array of strings, or a wildcard. It supports special JSON marshaling/unmarshaling behavior: - A single string (e.g., "value") is stored in the String field - An array of strings (e.g., ["val1", "val2"]) is stored in the Group field - The wildcard "*" is represented by setting Any to true
func (*SelectorElement) MarshalJSON ¶ added in v0.5.0
func (se *SelectorElement) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler for SelectorElement. It converts the selector back to JSON: - Any=true becomes "*" - String field becomes a JSON string - Group field becomes a JSON array
func (*SelectorElement) UnmarshalJSON ¶ added in v0.5.0
func (se *SelectorElement) UnmarshalJSON(input []byte) error
UnmarshalJSON implements json.Unmarshaler for SelectorElement. It handles three formats: - A JSON string (converted to String field, or Any if "*") - A JSON array (converted to Group field) - Any other format returns an error