tokenduration

package
v1.78.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TokenDuration

type TokenDuration time.Duration

TokenDuration wraps time.Duration to provide custom parsing for token lifetimes. It supports parsing duration strings with h (hours), d (days), and w (weeks) suffixes. This type implements the pflag.Value interface for use with Cobra commands.

func ParseDuration

func ParseDuration(s string) (TokenDuration, error)

ParseDuration parses a duration string with support for hours (h), days (d), and weeks (w). It accepts formats like: "24h", "30d", "2w", "720h". The duration must be a whole number of days and between 1 and 365 days.

func (TokenDuration) CalculateExpirationDate

func (d TokenDuration) CalculateExpirationDate() time.Time

CalculateExpirationDate calculates an expiration date by adding the duration to today's date. It uses date-only arithmetic (AddDate) since token expiration dates are dates without times. Returns a time.Time at midnight UTC representing the expiration date.

func (TokenDuration) Duration

func (d TokenDuration) Duration() time.Duration

Duration returns the underlying time.Duration value.

func (*TokenDuration) Set

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

Set parses the given value and sets this TokenDuration. The Set() function is required for Cobra to parse command line arguments.

func (TokenDuration) String

func (d TokenDuration) String() string

String returns the duration formatted as a string. The String() function is required for Cobra to display the default value.

func (*TokenDuration) Type

func (d *TokenDuration) Type() string

Type returns the type name for help text. The Type() function is required for Cobra to display type information in help.

Jump to

Keyboard shortcuts

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