Help us shape the future of Go! Take the 2026 Go Developer Survey

duration

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package duration provides a time.Duration that crosses JSON as a Go duration string ("5s") rather than a nanosecond count.

Plain time.Duration is enough for YAML-only config: yaml.v3 already reads and writes duration strings and rejects bare numbers. Use Duration when the value also travels as JSON or is described by a reflected JSON schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration time.Duration

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) JSONSchema

func (Duration) JSONSchema() *jsonschema.Schema

JSONSchema describes the wire form; without it the reflector reports the underlying int64.

func (Duration) MarshalText

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

MarshalText also serves yaml.v3, which falls back to encoding.TextMarshaler.

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalText

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

func (*Duration) UnmarshalYAML

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

UnmarshalYAML rejects bare numbers, which UnmarshalText alone would accept for "0", and names the mistake: an author who writes "timeout: 5" almost always means seconds.

Jump to

Keyboard shortcuts

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