duration

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package duration provides a Duration type that supports string-based and numeric YAML/JSON marshalling. It wraps time.Duration and is intended for use in any configuration struct that needs human-readable durations like "30s", "2m", or "1m30s". Numeric values (nanoseconds) are also accepted during unmarshalling for backward compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	time.Duration
}

Duration is a time.Duration with string-based YAML/JSON marshalling. Supports Go duration strings like "30s", "2m", "1m30s". Numeric values (nanoseconds) are accepted during unmarshalling.

func New

func New(d time.Duration) Duration

New creates a Duration from a time.Duration.

func NewPtr

func NewPtr(d time.Duration) *Duration

NewPtr creates a *Duration from a time.Duration.

func (Duration) MarshalJSON

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

MarshalJSON implements json.Marshaler for Duration.

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler for Duration.

func (*Duration) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for Duration. Accepts both string durations ("30s") and numeric nanoseconds (1000000000).

func (*Duration) UnmarshalYAML

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

UnmarshalYAML implements yaml.Unmarshaler for Duration. Accepts both string durations ("30s") and integer nanoseconds (1000000000).

Jump to

Keyboard shortcuts

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