utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB int64 = 1 << (10 * iota)
	MB
	GB
	TB
)

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(b uint64) string

FormatBytes converts bytes to a human-readable string (e.g., 1.5 MiB).

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the configured global logger. Should generally not be needed if slog.Default() is used throughout.

func InitLogger

func InitLogger(verbose bool)

InitLogger initializes or re-initializes the global slog logger.

func NewDummyDirEntry

func NewDummyDirEntry(name string, size int64, mode fs.FileMode, modTime time.Time) fs.DirEntry

NewDummyDirEntry creates a synthetic fs.DirEntry. Mode should be the full os.FileMode.

func ParseFileSize

func ParseFileSize(sizeStr string) (int64, error)

ParseFileSize converts a human-readable file size string (e.g., "1MB", "500KB", "1024") to bytes. Supports K, M, G, T units (case-insensitive), with an optional 'B'. Also supports plain numbers for bytes. Allows fractional inputs like "0.5MB".

Types

type DummyDirEntry

type DummyDirEntry struct {
	// contains filtered or unexported fields
}

DummyDirEntry is a helper for creating fs.DirEntry for testing or specific scenarios

func (*DummyDirEntry) Info

func (d *DummyDirEntry) Info() (fs.FileInfo, error)

func (*DummyDirEntry) IsDir

func (d *DummyDirEntry) IsDir() bool

func (*DummyDirEntry) Name

func (d *DummyDirEntry) Name() string

func (*DummyDirEntry) Type

func (d *DummyDirEntry) Type() fs.FileMode

Jump to

Keyboard shortcuts

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