add init functions

This commit is contained in:
2025-12-19 14:26:28 +02:00
parent c0a187d461
commit cd465d42a3
6 changed files with 81 additions and 1 deletions

View File

@@ -10,9 +10,13 @@ import (
type TokenStore interface {
revoke(tokenID string, expiresAt time.Time) error
isRevoked(tokenID string) (bool, error)
init() error
}
type Service struct {
initialized bool
cfg *config.Auth
store TokenStore
}
@@ -27,6 +31,24 @@ func NewTokenService(cfg *config.Auth, store TokenStore) (*Service, error) {
return &Service{cfg: cfg, store: store}, nil
}
func (s *Service) isInitialized() bool {
return s.initialized
}
func (s *Service) Init() error {
if s.isInitialized() {
return nil
}
err := s.store.init()
if err != nil {
return fmt.Errorf("failed to initialize token store: %w", err)
}
s.initialized = true
return nil
}
func (s *Service) Revoke(jti string, exp time.Time) error {
return s.store.revoke(jti, exp)
}