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

duration

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package duration parses Go duration syntax plus d for days of 24 hours.

Index

Constants

View Source
const DefaultPublicMax = 7 * 24 * time.Hour
View Source
const Examples = "90m, 36h, 3d, 1w, 1d12h, until 2030-06-01, until 2030-06-01T18:00, until 2030-06-01T18:00:00Z, never"
View Source
const Suggestions = "1h, 8h, 24h, 3d, 7d"

Variables

This section is empty.

Functions

func Parse

func Parse(value string) (time.Duration, error)

Parse reads Go duration syntax extended with d for days, ignoring surrounding space.

func ParseRelative

func ParseRelative(value string) (time.Duration, error)

ParseRelative accepts positive decimal components in strictly descending unit order. Exact rational arithmetic rejects overflow and sub-nanoseconds. Days and weeks are elapsed 24h and 168h, including across DST transitions.

Types

type Audience

type Audience string
const (
	TailnetMember Audience = "tailnet_member"
	Guest         Audience = "guest"
	Public        Audience = "public"
)

type Lifetime

type Lifetime struct {
	Deadline *time.Time
	Never    bool
}

Lifetime has exactly one representation: a UTC deadline, or Never.

func ParseLifetime

func ParseLifetime(value string, now time.Time, loc *time.Location) (Lifetime, error)

ParseLifetime never reads wall time. loc nil means time.Local. Local gaps and folds are refused: the owner must supply an RFC3339 offset to choose an instant.

type Policy

type Policy struct{ PublicMax time.Duration }

Policy is shared by people, Funnel, and future guest/approval callers. A zero PublicMax selects the default. Policy validation never uses wall time.

func (Policy) Check

func (p Policy) Check(l Lifetime, audience Audience, acknowledgeNever bool, now time.Time) error

func (Policy) Resolve

func (p Policy) Resolve(value string, audience Audience, acknowledgeNever bool, now time.Time, loc *time.Location) (Lifetime, error)

func (Policy) Validate

func (p Policy) Validate() error

type Value

type Value time.Duration

Value is a duration flag that reads Parse and retains pflag's duration type.

func NewValue

func NewValue(value time.Duration) *Value

NewValue returns a flag with the given default.

func (*Value) Set

func (d *Value) Set(value string) error

func (*Value) String

func (d *Value) String() string

func (*Value) Type

func (d *Value) Type() string

Jump to

Keyboard shortcuts

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