Documentation
¶
Index ¶
- Constants
- type DefaultService
- func (d *DefaultService) Connect() error
- func (d *DefaultService) DB() (*sql.DB, error)
- func (d *DefaultService) Disconnect() error
- func (d *DefaultService) Start(ctx context.Context) error
- func (d *DefaultService) Validate(jti string) (bool, error)
- func (d *DefaultService) ValidateClaims(claims map[string]interface{}, token gojwttoken.Token) (bool, error)
- type Service
Constants ¶
View Source
const ( // CreateTableQuery is the SQL query to create the tokens table CreateTableQuery = `CREATE TABLE IF NOT EXISTS tokens (jti TEXT PRIMARY KEY)` // InsertTokenQuery is the SQL query to insert a new token InsertTokenQuery = `INSERT OR IGNORE INTO tokens (jti) VALUES (?)` // DeleteTokenQuery is the SQL query to delete a token DeleteTokenQuery = `DELETE FROM tokens WHERE jti = ?` // CheckTokenQuery is the SQL query to check if a token exists CheckTokenQuery = `SELECT COUNT(1) FROM tokens WHERE jti = ?` )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultService ¶
type DefaultService struct {
godatabasessql.Handler
// contains filtered or unexported fields
}
DefaultService is the default implementation of the Service interface
func NewDefaultService ¶
func NewDefaultService( handler godatabasessql.Handler, consumer gojwtrabbitmqconsumer.Consumer, logger *slog.Logger, ) (*DefaultService, error)
NewDefaultService creates a new DefaultService
Parameters:
- handler: the SQL connection handler
- consumer: the RabbitMQ consumer
- logger: the logger (optional, can be nil)
Returns:
- *DefaultService: the DefaultService instance
- error: an error if the data source or driver name is empty
func (*DefaultService) Connect ¶
func (d *DefaultService) Connect() error
Connect opens the database connection
Returns:
- error: an error if the connection could not be opened
func (*DefaultService) DB ¶
func (d *DefaultService) DB() (*sql.DB, error)
DB is a helper function to get the database connection
Returns:
- *sql.DB: the database connection
func (*DefaultService) Disconnect ¶
func (d *DefaultService) Disconnect() error
Disconnect closes the database connection
Returns:
- error: an error if the connection could not be closed
func (*DefaultService) Start ¶
func (d *DefaultService) Start(ctx context.Context) error
Start starts the service to listen for messages and update the SQLite database
Parameters:
- ctx: the context for managing cancellation and timeouts
Returns:
- error: an error if the service could not be started
func (*DefaultService) Validate ¶
func (d *DefaultService) Validate(jti string) (bool, error)
Validate checks if the given JTI exists in the database
Parameters:
- jti: the JTI to validate
Returns:
- bool: true if the JTI exists, false otherwise
- error: an error if the validation could not be performed
func (*DefaultService) ValidateClaims ¶
func (d *DefaultService) ValidateClaims( claims map[string]interface{}, token gojwttoken.Token, ) (bool, error)
ValidateClaims validates the JWT claims
Parameters:
- claims: the JWT claims to validate
- token: the token type
Returns:
- bool: true if the claims are valid, false otherwise
- error: an error if the validation could not be performed
Click to show internal directories.
Click to hide internal directories.