unit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 6 Imported by: 2

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 marshaled/unmarshaled as a string in JSON. It supports both numeric values (interpreted as nanoseconds) and string values (e.g., "5m", "1h30m").

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the time.Duration value.

func (Duration) MarshalJSON

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

MarshalJSON marshals the Duration to a JSON string representation (e.g., "5m30s").

func (*Duration) UnmarshalJSON

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

UnmarshalJSON unmarshals a JSON value to Duration. It accepts both numeric values (interpreted as nanoseconds) and string values (e.g., "5m", "1h30m").

type Percentage

type Percentage struct {
	Number    int  `json:",omitempty"`
	HasSuffix bool `json:",omitempty"`
}

Percentage represents a percentage value that can be represented with or without a % suffix. It stores both the numeric value and whether it originally had a % suffix.

func (Percentage) Int

func (p Percentage) Int() int

Int returns the numeric value of the percentage.

func (Percentage) MarshalJSON

func (p Percentage) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Percentage to a JSON string representation.

func (Percentage) String

func (p Percentage) String() string

String returns the string representation of the percentage. If HasSuffix is true, it includes the % suffix.

func (*Percentage) UnmarshalJSON

func (p *Percentage) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON string to Percentage. It accepts both plain numbers (e.g., "50") and percentage strings (e.g., "50%").

type Replicas

type Replicas struct {
	Number       int
	IsPercentage bool
}

Replicas represents a replica count that can be either an absolute number or a percentage. When IsPercentage is true, Number represents a percentage value.

func (Replicas) Calculate

func (r Replicas) Calculate(total, defaultValue int) int

Calculate returns the actual replica count based on the total replicas. If the replica is a percentage, it calculates the ceiling of (Number * total / 100). If Number is 0, it returns the defaultValue. If IsPercentage is false, it returns the Number directly.

func (Replicas) MarshalJSON

func (r Replicas) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Replicas to a JSON string representation.

func (Replicas) String

func (r Replicas) String() string

String returns the string representation of the replicas. If IsPercentage is true, it includes the % suffix.

func (*Replicas) UnmarshalJSON

func (r *Replicas) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON value to Replicas. It accepts numeric values, string numbers (e.g., "5"), and percentage strings (e.g., "50%").

Jump to

Keyboard shortcuts

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