Documentation ¶
Index ¶
- func GenerateCode() string
- func GetTime() int64
- type CodeStore
- func (c *CodeStore) CleanExpired()
- func (c *CodeStore) Close()
- func (c *CodeStore) ExchangeCode(code string) (permission.Token, error)
- func (c *CodeStore) GetCodeCount() int
- func (c *CodeStore) GetTTL() int64
- func (c *CodeStore) GetTime() int64
- func (c *CodeStore) SubmitToken(token permission.Token) string
- func (c *CodeStore) WithTTL(ttl int64) *CodeStore
- type ExpToken
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
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) ExchangeCode ¶
func (c *CodeStore) ExchangeCode(code string) (permission.Token, error)
ExchangeCode swaps a (valid) code for the associated token.
func (*CodeStore) GetCodeCount ¶
GetCodeCount counts the number of tokens in the store
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.
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
Click to show internal directories.
Click to hide internal directories.