duration

package
v0.95.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 5 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 struct {
	// contains filtered or unexported fields
}

Duration is a wrapper for durationpb.Duration to provide custom marshaling for JSON and URL query strings.

It embeds durationpb.Duration and exposes the .AsDuration() method to easily convert to time.Duration.

Example:

customDur := duration.New(30 * time.Second)
goDur := customDur.AsDuration()

func New

func New(d time.Duration) *Duration

New creates a custom Duration from a standard time.Duration.

func (*Duration) AsDuration

func (x *Duration) AsDuration() time.Duration

AsDuration returns the underlying time.Duration value.

func (Duration) EncodeValues

func (d Duration) EncodeValues(key string, v *url.Values) error

EncodeValues implements the [query.Encoder] interface by encoding the duration as a string, like "3.3s".

func (Duration) MarshalJSON

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

MarshalJSON implements the [json.Marshaler] interface by marshalling the duration as a protobuf Duration.

func (*Duration) UnmarshalJSON

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

UnmarshalJSON implements the [json.Unmarshaler] interface. It can parse a duration from the protobuf Duration.

Jump to

Keyboard shortcuts

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