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

ttlcode

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCode

func GenerateCode() string

GenerateCode returns a unique string to be used as a code

func GetTime

func GetTime() int64

GetTime gets the current Unix time in seconds.

Types

type CodeStore

type CodeStore struct {
	// Prevent multiple clients getting the same token by mutexing.
	sync.Mutex
	// contains filtered or unexported fields
}

CodeStore represents the codes, and their associated expiring tokens.

func NewDefaultCodeStore

func NewDefaultCodeStore() *CodeStore

NewDefaultCodeStore returns a codestore with code lifetime of 30seconds.

func (*CodeStore) CleanExpired

func (c *CodeStore) CleanExpired()

CleanExpired removes stale codes & tokens from the CodeStore

func (*CodeStore) Close

func (c *CodeStore) Close()

Close stops the codestore

func (*CodeStore) ExchangeCode

func (c *CodeStore) ExchangeCode(code string) (permission.Token, error)

ExchangeCode swaps a (valid) code for the associated token.

func (*CodeStore) GetCodeCount

func (c *CodeStore) GetCodeCount() int

GetCodeCount counts the number of tokens in the store

func (*CodeStore) GetTTL

func (c *CodeStore) GetTTL() int64

GetTTL returns the TTL for the codestore

func (*CodeStore) GetTime

func (c *CodeStore) GetTime() int64

GetTime gets the current time as used by the CodeStore

func (*CodeStore) SubmitToken

func (c *CodeStore) SubmitToken(token permission.Token) string

SubmitToken returns a code that can be swapped for the token, until the code/token becomes stale.

func (*CodeStore) WithTTL

func (c *CodeStore) WithTTL(ttl int64) *CodeStore

WithTTL sets the code lifetime of the new CodeStore (in seconds).

type ExpToken

type ExpToken struct {

	// Token represents a token of arbitrary type.
	Token permission.Token

	// Exp represents the expiry Unix time in seconds.
	Exp int64
}

ExpToken represents a token and its expiry time. Tokens are assumed valid from time of submission.

func NewExpToken

func NewExpToken(token permission.Token, ttl int64) ExpToken

NewExpToken creates a new token expiring in ttl seconds from now

func (*ExpToken) Expired

func (t *ExpToken) Expired() bool

Expired returns true if the token has expired.

Jump to

Keyboard shortcuts

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