Documentation
¶
Index ¶
- Variables
- func GetTokenFromCache(token gojwttoken.Token, id int64, logger *slog.Logger)
- func GetTokenFromCacheFailed(err error, logger *slog.Logger)
- func RevokeTokenFromCache(token gojwttoken.Token, id int64, logger *slog.Logger)
- func RevokeTokenFromCacheFailed(err error, logger *slog.Logger)
- func SetTokenToCache(token gojwttoken.Token, id int64, logger *slog.Logger)
- func SetTokenToCacheFailed(err error, logger *slog.Logger)
- type TokenValidator
- type TokenValidatorService
- func (t *TokenValidatorService) GetKey(token gojwttoken.Token, id string) (string, error)
- func (t *TokenValidatorService) IsValid(token gojwttoken.Token, id string) (bool, error)
- func (t *TokenValidatorService) Revoke(token gojwttoken.Token, id string) error
- func (t *TokenValidatorService) Set(token gojwttoken.Token, id string, isValid bool, expiresAt time.Time) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrNilTokenValidator = errors.New("nil token validator")
)
var ( // JwtIdentifierSeparator is the separator of the JWT identifier prefixes JwtIdentifierSeparator = gostringsseparator.Dots )
Functions ¶
func GetTokenFromCache ¶ added in v0.5.0
func GetTokenFromCache(token gojwttoken.Token, id int64, logger *slog.Logger)
GetTokenFromCache logs the get token from cache event
Parameters:
- token: The token being retrieved from cache
- id: The ID associated with the token
- logger: The logger to use for logging (optional, can be nil)
func GetTokenFromCacheFailed ¶ added in v0.5.0
GetTokenFromCacheFailed logs the get token from cache failed event
Parameters:
- err: The error that occurred while retrieving the token from cache
- logger: The logger to use for logging (optional, can be nil)
func RevokeTokenFromCache ¶ added in v0.5.0
func RevokeTokenFromCache( token gojwttoken.Token, id int64, logger *slog.Logger, )
RevokeTokenFromCache logs the revoke token from cache event
Parameters:
- token: The token being revoked from cache
- id: The ID associated with the token
- logger: The logger to use for logging (optional, can be nil)
func RevokeTokenFromCacheFailed ¶ added in v0.5.0
RevokeTokenFromCacheFailed logs the revoke token from cache failed event
Parameters:
- err: The error that occurred while revoking the token from cache
- logger: The logger to use for logging (optional, can be nil)
func SetTokenToCache ¶ added in v0.5.0
func SetTokenToCache(token gojwttoken.Token, id int64, logger *slog.Logger)
SetTokenToCache logs the set token to cache event
Parameters:
- token: The token being set to cache
- id: The ID associated with the token
- logger: The logger to use for logging (optional, can be nil)
func SetTokenToCacheFailed ¶ added in v0.5.0
SetTokenToCacheFailed logs the set token to cache failed event
Parameters:
- err: The error that occurred while setting the token to cache
- logger: The logger to use for logging (optional, can be nil)
Types ¶
type TokenValidator ¶
type TokenValidator interface {
Set(
token gojwttoken.Token,
id string,
isValid bool,
expiresAt time.Time,
) error
Revoke(token gojwttoken.Token, id string) error
IsValid(token gojwttoken.Token, id string) (bool, error)
}
TokenValidator interface
type TokenValidatorService ¶
type TokenValidatorService struct {
// contains filtered or unexported fields
}
TokenValidatorService struct
func NewTokenValidatorService ¶
func NewTokenValidatorService(logger *slog.Logger) *TokenValidatorService
NewTokenValidatorService creates a new token validator service
Parameters:
- logger: The logger (optional, can be nil)
Returns:
- *TokenValidatorService: The token validator service
func (*TokenValidatorService) GetKey ¶ added in v0.4.2
func (t *TokenValidatorService) GetKey( token gojwttoken.Token, id string, ) (string, error)
GetKey gets the key for the cache
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- string: The key for the cache
- error: An error if the token validator service is nil or if the token abbreviation fails
func (*TokenValidatorService) IsValid ¶ added in v0.4.7
func (t *TokenValidatorService) IsValid( token gojwttoken.Token, id string, ) (bool, error)
IsValid checks if a token is valid in the cache
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- bool: Whether the token is valid
- error: An error if the token validator service is nil or if checking the token in the cache fails
func (*TokenValidatorService) Revoke ¶ added in v0.4.7
func (t *TokenValidatorService) Revoke( token gojwttoken.Token, id string, ) error
Revoke revokes a token in the cache
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- error: An error if the token validator service is nil or if revoking the token in the cache fails
func (*TokenValidatorService) Set ¶
func (t *TokenValidatorService) Set( token gojwttoken.Token, id string, isValid bool, expiresAt time.Time, ) error
Set sets a token in the cache
Parameters:
- token: The token
- id: The ID associated with the token
- isValid: Whether the token is valid
- expiresAt: The expiration time of the token
Returns:
- error: An error if the token validator service is nil or if setting the token in the cache fails