types

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration time.Duration

Duration represents a time duration that can be parsed from various string formats and provides type-safe operations. It stores the duration internally as time.Duration.

func MustParseDuration

func MustParseDuration(s string) Duration

MustParseDuration parses a duration string and panics on error

func NewDuration

func NewDuration(s string) Duration

NewDuration creates a Duration from a string, intended for known-valid values

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration creates a Duration from a string representation (e.g., "5min", "30s", "1h")

func (Duration) Add

func (d Duration) Add(other Duration) Duration

Add adds another duration to this one

func (Duration) Div

func (d Duration) Div(factor float64) Duration

Div divides the duration by a factor

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the underlying time.Duration

func (Duration) Hours

func (d Duration) Hours() float64

Hours returns the duration as hours

func (Duration) IsZero

func (d Duration) IsZero() bool

IsZero returns true if the duration is zero

func (Duration) MarshalJSON

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

MarshalJSON implements json.Marshaler interface

func (Duration) MarshalText

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

MarshalText implements encoding.TextMarshaler interface (for koanf)

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface

func (Duration) Microseconds

func (d Duration) Microseconds() int64

Microseconds returns the duration as microseconds

func (Duration) Milliseconds

func (d Duration) Milliseconds() int64

Milliseconds returns the duration as milliseconds

func (Duration) Minutes

func (d Duration) Minutes() float64

Minutes returns the duration as minutes

func (Duration) Mul

func (d Duration) Mul(factor float64) Duration

Mul multiplies the duration by a factor

func (Duration) Nanoseconds

func (d Duration) Nanoseconds() int64

Nanoseconds returns the duration as nanoseconds

func (Duration) PostgreSQLString

func (d Duration) PostgreSQLString() string

PostgreSQLString returns a PostgreSQL-compatible string representation

func (Duration) Round

func (d Duration) Round(precision time.Duration) Duration

Round rounds the duration to the nearest multiple of precision

func (Duration) Seconds

func (d Duration) Seconds() float64

Seconds returns the duration as seconds

func (Duration) String

func (d Duration) String() string

String returns a human-readable string representation

func (Duration) Sub

func (d Duration) Sub(other Duration) Duration

Sub subtracts another duration from this one

func (Duration) Truncate

func (d Duration) Truncate(precision time.Duration) Duration

Truncate truncates the duration to the specified precision

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

func (*Duration) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler interface (for koanf)

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface

type Size

type Size uint64

Size represents a memory or storage size that can be parsed from various string formats and provides type-safe operations. It stores the size internally as bytes.

const (
	KB Size = 1024
	MB Size = 1024 * KB
	GB Size = 1024 * MB
	TB Size = 1024 * GB
)

func MustParseSize

func MustParseSize(s string) Size

MustParseSize parses a size string and panics on error

func NewSize

func NewSize(s string) Size

NewSize creates a Size from a string, intended for known-valid values

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize creates a Size from a string representation (e.g., "128MB", "1GB", "512kB")

func (Size) Add

func (s Size) Add(other Size) Size

Add adds another size to this one

func (Size) Bytes

func (s Size) Bytes() uint64

Bytes returns the size in bytes

func (Size) Div

func (s Size) Div(factor float64) Size

Div divides the size by a factor

func (Size) Format added in v1.0.4

func (s Size) Format(f fmt.State, verb rune)

func (Size) GB

func (s Size) GB() uint64

GB returns the size in gigabytes

func (Size) IsZero

func (s Size) IsZero() bool

IsZero returns true if the size is zero

func (Size) KB

func (s Size) KB() uint64

KB returns the size in kilobytes

func (Size) MB

func (s Size) MB() uint64

MB returns the size in megabytes

func (Size) MarshalJSON

func (s Size) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (Size) MarshalText

func (s Size) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface (for koanf)

func (Size) MarshalYAML

func (s Size) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface

func (Size) Mul

func (s Size) Mul(factor float64) Size

Mul multiplies the size by a factor

func (Size) PostgreSQLMB

func (s Size) PostgreSQLMB() string

PostgreSQLMB returns a PostgreSQL-compatible string representation in MB units

func (Size) PostgreSQLString

func (s Size) PostgreSQLString() string

PostgreSQLString returns a PostgreSQL-compatible string representation

func (Size) String

func (s Size) String() string

func (Size) Sub

func (s Size) Sub(other Size) Size

Sub subtracts another size from this one

func (*Size) UnmarshalJSON

func (s *Size) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

func (*Size) UnmarshalText

func (s *Size) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface (for koanf)

func (*Size) UnmarshalYAML

func (s *Size) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface

Jump to

Keyboard shortcuts

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