// gen generates a new token. Provided values determine the expiration time
// and the time when another token will be allowed to be generated.
gen generates a new token. Provided values determine the expiration time
and the time when another token will be allowed to be generated.
// gen generates a new token . Provided values determine the expiration time // and the time when another token will be allowed to be generated .
func (t *Token) gen(tl TokenLifetime) (string, error) {
	if timeutil.Now().Before(t.NextAt.Time) {
		return "", ErrTooManyTokens
	}
	v := uniuri.NewLenChars(uniuri.StdLen, _tokenChars)
	h, err := bcrypt.GenerateFromPassword([]byte(v), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	t.ExpiresAt = null.TimeFrom(timeutil.Now().Add(tl.Interval))
	t.NextAt = null.TimeFrom(timeutil.Now().Add(tl.Cooldown))
	t.Hash = h
	return v, nil
}
func ( t * Token ) gen ( tl TokenLifetime ) ( string , error ) { if timeutil . Now ( ) . Before ( t . NextAt . Time ) { return " " , ErrTooManyTokens } v := uniuri . NewLenChars ( uniuri . StdLen , _tokenChars ) h , err := bcrypt . GenerateFromPassword ( [ ] byte ( v ) , bcrypt . DefaultCost ) if err != nil { return " " , err } t . ExpiresAt = null . TimeFrom ( timeutil . Now ( ) . Add ( tl . Interval ) ) t . NextAt = null . TimeFrom ( timeutil . Now ( ) . Add ( tl . Cooldown ) ) t . Hash = h return v , nil }
gen generates a new token.
gen generates a new token .
// unlikely to happen