add init functions
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user