util

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr added in v0.4.0

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given bool

func BytesToGB added in v0.3.0

func BytesToGB[T ~int | ~int64 | ~float64](bytes T) int

BytesToGB converts a value in bytes to gigabytes (GB). Accepts int, int64, or float64.

func BytesToTB added in v0.3.0

func BytesToTB[T ~int | ~int64 | ~float64](bytes T) float64

BytesToTB converts a value in bytes to terabytes (TB). Accepts int, int64, or float64.

func Contains

func Contains(slice []string, val string) bool

Contains checks if a slice contains a specific string

func ConvertBytesToMB

func ConvertBytesToMB(bytes int64) int64

ConvertBytesToMB converts bytes to megabytes safely

func ConvertMBToBytes

func ConvertMBToBytes(mb int64) int64

ConvertMBToBytes converts megabytes to bytes safely

func DerefString

func DerefString(s *string) string

DerefString safely dereferences a string pointer, returning an empty string if the pointer is nil

func FloatPtr added in v0.3.0

func FloatPtr(i float64) *float64

FloatPtr returns a pointer to the given float

func GBToTB added in v0.3.0

func GBToTB[T ~int | ~int64 | ~float64](gb T) float64

GBToTB converts a value in gigabytes (GB) to terabytes (TB). Accepts int, int64, or float64.

func GetEnv

func GetEnv(key, defaultValue string) string

func GetIntEnv

func GetIntEnv(key string, defaultValue uint) (uint, error)

func GetInventoryVersion added in v0.4.0

func GetInventoryVersion(inventory []byte) int

Unmarshal does not return error when v1 inventory is unmarshal into a v2 struct. The only way to differentiate the version is to check the internal structure.

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to the given int

func MBToGB added in v0.3.0

func MBToGB[T ~int | ~int32 | ~float64](mb T) int

MBToGB converts a value in MB to GB. Accepts int, int32, or float64.

func Must

func Must(err error)

func MustString

func MustString(fn StringerWithError) string

func Round added in v0.3.0

func Round(f float64) float64

Round Method to round to 2 decimals

func ToStrPtr

func ToStrPtr(s string) *string

ToStrPtr returns a pointer to the given string

func ValidateInventoryHasVMs added in v0.4.0

func ValidateInventoryHasVMs(inventory []byte) error

ValidateInventoryHasVMs validates that inventory has at least one VM Returns typed errors to distinguish between validation failures and data corruption

Types

type Duration

type Duration struct {
	time.Duration
}

func (*Duration) UnmarshalJSON

func (duration *Duration) UnmarshalJSON(b []byte) error

type ErrEmptyInventory added in v0.4.0

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

ErrEmptyInventory indicates the inventory data is empty

type ErrInventoryUnmarshalError added in v0.4.0

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

ErrInventoryUnmarshalError indicates the inventory data cannot be unmarshaled (corrupted data)

type ErrNoVMsInInventory added in v0.4.0

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

ErrNoVMsInInventory indicates the inventory has no VMs (validation failure)

type StringerWithError

type StringerWithError func() (string, error)

Jump to

Keyboard shortcuts

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