scalar

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoerceNumber

func CoerceNumber[T any](val any) (T, bool)

CoerceNumber converts any numeric value into the requested target type T.

func ToFloat64

func ToFloat64(val any) (float64, bool)

ToFloat64 safely converts any primitive numeric type to a float64.

func ToInt64

func ToInt64(val any) (int64, bool)

ToInt64 safely converts any primitive numeric type to an int64.

Types

type ByteSize

type ByteSize int64

ByteSize represents a quantity of bytes that unmarshals from human-readable text.

const (
	B   ByteSize = 1
	KB  ByteSize = 1000 * B
	KiB ByteSize = 1024 * B
	MB  ByteSize = 1000 * KB
	MiB ByteSize = 1024 * KiB
	GB  ByteSize = 1000 * MB
	GiB ByteSize = 1024 * MiB
	TB  ByteSize = 1000 * GB
	TiB ByteSize = 1024 * GiB
)

ByteSize constants.

func ParseByteSize

func ParseByteSize(s string) (ByteSize, error)

ParseByteSize parses a string containing byte quantities (e.g. "25MB", "1.5GiB", "1048576").

func (ByteSize) Bytes

func (b ByteSize) Bytes() int64

Bytes returns the size in raw bytes as an int64.

func (ByteSize) MarshalText

func (b ByteSize) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ByteSize) String

func (b ByteSize) String() string

String returns a human-readable representation of the byte size.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (*ByteSize) UnmarshalYAML added in v0.2.0

func (b *ByteSize) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

type Duration

type Duration time.Duration

Duration wraps time.Duration with text and YAML unmarshaling.

func ParseDuration added in v0.1.3

func ParseDuration(s string) (Duration, error)

ParseDuration parses a human-readable duration string.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the underlying time.Duration.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Duration) String

func (d Duration) String() string

String returns the formatted duration string.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (*Duration) UnmarshalYAML added in v0.2.0

func (d *Duration) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}

Number represents all integer and floating-point numeric types.

Jump to

Keyboard shortcuts

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