bytesize

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bytesize parses free-space/capacity thresholds shared by internal/config (validating [disk] and cache-volume budget settings) and internal/diskguard (comparing them against live statfs results). It is a leaf package — it imports nothing internal — specifically so both of those packages can import it without an import cycle: internal/diskguard transitively imports internal/config (diskguard -> cachestore -> provider -> config), so internal/config cannot import internal/diskguard itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format added in v0.14.0

func Format(b uint64) string

Format renders a byte count for people: "512 B", "1.5 KiB", "2.0 GiB".

Types

type Threshold

type Threshold struct {
	Percent float64
	Bytes   uint64
}

Threshold is a free-space floor, expressed as either a percentage of the filesystem's total capacity or an absolute byte count. ParseThreshold only ever sets one of the two fields — BytesOf relies on that to decide which one applies.

func ParseThreshold

func ParseThreshold(s string) (Threshold, error)

ParseThreshold parses a free-space threshold: a percentage of total capacity like "10%" (0-100 inclusive), or an absolute size like "20GB" or "512MB" (binary units, case-insensitive: B/KB/MB/GB/TB).

func (Threshold) BytesOf

func (t Threshold) BytesOf(totalBytes uint64) uint64

BytesOf resolves this threshold against a filesystem's total capacity. An absolute threshold (Bytes != 0) ignores totalBytes entirely; otherwise the percentage is scaled against it.

Jump to

Keyboard shortcuts

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