units

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseQuantityString

func ParseQuantityString(str string) (positive bool, value, num, denom, suffix string, err error)

ParseQuantityString is a fast scanner for quantity values. this parsing is only for cpu and mem resources

func ParseValAndUnit

func ParseValAndUnit(quantity string) (float64, string, error)

ParseValAndUnit parses the quantity which have number values string and returns the value and unit returns error if parsing fails

Types

type CPUUnitStr

type CPUUnitStr string
const (
	CORE  CPUUnitStr = "Core"
	MILLI CPUUnitStr = "m"
)

func (CPUUnitStr) GetCPUUnit

func (cpuUnitStr CPUUnitStr) GetCPUUnit() UnitSuffix

type MemoryUnitStr

type MemoryUnitStr string
const (
	MILLIBYTE MemoryUnitStr = "m"
	BYTE      MemoryUnitStr = "byte"
	KIBYTE    MemoryUnitStr = "Ki"
	MIBYTE    MemoryUnitStr = "Mi"
	GIBYTE    MemoryUnitStr = "Gi"
	TIBYTE    MemoryUnitStr = "Ti"
	PIBYTE    MemoryUnitStr = "Pi"
	EIBYTE    MemoryUnitStr = "Ei"
	KBYTE     MemoryUnitStr = "k"
	MBYTE     MemoryUnitStr = "M"
	GBYTE     MemoryUnitStr = "G"
	TBYTE     MemoryUnitStr = "T"
	PBYTE     MemoryUnitStr = "P"
	EBYTE     MemoryUnitStr = "E"
)

func (MemoryUnitStr) GetMemoryUnit

func (memoryUnitStr MemoryUnitStr) GetMemoryUnit() UnitSuffix

type TimeUnitStr

type TimeUnitStr string
const (
	SecondStr TimeUnitStr = "Seconds"
	MinuteStr TimeUnitStr = "Minutes"
	HourStr   TimeUnitStr = "Hours"
)

func (TimeUnitStr) GetTimeUnit

func (timeUnitStr TimeUnitStr) GetTimeUnit() UnitSuffix

type Unit

type Unit struct {
	// Name is unit name
	Name string `json:"name"`
	// ConversionFactor is used to convert this unit to the base unit
	// if ConversionFactor is 1, then this is the base unit
	ConversionFactor float64 `json:"conversionFactor"`
}

Unit represents unit of a configuration

type UnitStr

type UnitStr interface {
	CPUUnitStr | MemoryUnitStr | TimeUnitStr
}

type UnitSuffix

type UnitSuffix int
const (
	Byte      UnitSuffix = 1
	KiByte    UnitSuffix = 2 // 1024
	MiByte    UnitSuffix = 3
	GiByte    UnitSuffix = 4
	TiByte    UnitSuffix = 5
	PiByte    UnitSuffix = 6
	EiByte    UnitSuffix = 7
	K         UnitSuffix = 8 // 1000
	M         UnitSuffix = 9
	G         UnitSuffix = 10
	T         UnitSuffix = 11
	P         UnitSuffix = 12
	E         UnitSuffix = 13
	Core      UnitSuffix = 14 // CPU cores
	Milli     UnitSuffix = 15
	Second    UnitSuffix = 16
	Minute    UnitSuffix = 17
	Hour      UnitSuffix = 18
	MilliByte UnitSuffix = 19
)

func (UnitSuffix) GetCPUUnitStr

func (cpuUnit UnitSuffix) GetCPUUnitStr() CPUUnitStr

func (UnitSuffix) GetMemoryUnitStr

func (memoryUnit UnitSuffix) GetMemoryUnitStr() MemoryUnitStr

func (UnitSuffix) GetTimeUnitStr

func (timeUnit UnitSuffix) GetTimeUnitStr() TimeUnitStr

type Units

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

func NewUnits

func NewUnits() *Units

func (*Units) GetCpuUnits

func (u *Units) GetCpuUnits() map[CPUUnitStr]Unit

func (*Units) GetMemoryUnits

func (u *Units) GetMemoryUnits() map[MemoryUnitStr]Unit

func (*Units) GetTimeUnits

func (u *Units) GetTimeUnits() map[TimeUnitStr]Unit

Jump to

Keyboard shortcuts

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