resource

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KiB ByteQuantity = 1024
	MiB              = 1024 * KiB
	GiB              = 1024 * MiB
	TiB              = 1024 * GiB
	PiB              = 1024 * TiB
	EiB              = 1024 * PiB
)

Binary SI size constants.

View Source
const (
	UnitKiB = "KiB"
	UnitMiB = "MiB"
	UnitGiB = "GiB"
	UnitTiB = "TiB"
	UnitPiB = "PiB"
	UnitEiB = "EiB"
)

Unit suffix constants for use with FormatByteQuantity.

Variables

This section is empty.

Functions

func FormatByteQuantity

func FormatByteQuantity(b ByteQuantity, unit string) string

FormatByteQuantity formats b in the given binary SI unit (use the UnitXiB constants). "" formats as plain bytes. Example: FormatByteQuantity(8*GiB, UnitGiB) → "8GiB".

func FormatMillicores

func FormatMillicores(m Millicores, unit string) string

FormatMillicores formats m in the given decimal SI unit prefix. unit: "m" (millicores), "" (whole cores). Example: FormatMillicores(1000, "m") → "1000m", FormatMillicores(1000, "") → "1".

Types

type ByteQuantity

type ByteQuantity int64

ByteQuantity stores a memory quantity as int64 bytes (the smallest unit). Implements pflag.Value for use with cmd.Flags().Var().

func ParseByteQuantity

func ParseByteQuantity(s string) (ByteQuantity, error)

ParseByteQuantity parses a byte quantity string. Accepts E/Ei/EiB, P/Pi/PiB, T/Ti/TiB, G/Gi/GiB, M/Mi/MiB, K/Ki/KiB, or bare integer (treated as GiB).

func (ByteQuantity) GiB

func (b ByteQuantity) GiB() int64

GiB returns the quantity as an integer number of gibibytes (truncating).

func (*ByteQuantity) Set

func (b *ByteQuantity) Set(s string) error

Set implements pflag.Value.

func (ByteQuantity) String

func (b ByteQuantity) String() string

String implements pflag.Value. Auto-picks the largest binary SI unit that divides evenly: 8*GiB → "8GiB". Returns "" for zero.

func (*ByteQuantity) Type

func (b *ByteQuantity) Type() string

Type implements pflag.Value.

type Millicores

type Millicores int64

Millicores stores a CPU/GPU quantity as int64 millicores (the smallest unit). Implements pflag.Value for use with cmd.Flags().Var().

func ParseMillicores

func ParseMillicores(s string) (Millicores, error)

ParseMillicores parses a millicore string. "1" → 1000, "0.5" → 500, "1000m" → 1000.

func (*Millicores) Set

func (m *Millicores) Set(s string) error

Set implements pflag.Value.

func (Millicores) String

func (m Millicores) String() string

String implements pflag.Value. Auto-picks the best decimal SI unit: 1000 → "1", 500 → "500m". Returns "" for zero.

func (*Millicores) Type

func (m *Millicores) Type() string

Type implements pflag.Value.

Jump to

Keyboard shortcuts

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