scalar

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 6 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 can be unmarshaled from 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 represent byte sizes.

func ParseByteSize

func ParseByteSize(s string) (ByteSize, error)

ParseByteSize parses human-readable byte strings into a ByteSize.

func (ByteSize) Bytes

func (b ByteSize) Bytes() int64

Bytes returns the byte size as an integer.

func (ByteSize) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (ByteSize) String

func (b ByteSize) String() string

String returns the byte size as a human-readable string.

func (*ByteSize) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type Duration

type Duration time.Duration

Duration wraps a time.Duration with universal text deserialization.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the duration as a time.Duration.

func (Duration) MarshalText

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

MarshalText implements the encoding.TextMarshaler interface.

func (Duration) String

func (d Duration) String() string

String returns the duration as a human-readable string.

func (*Duration) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

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