Documentation
¶
Index ¶
- type DBSecondaryStorage
- type InMemorySecondaryStorage
- func (s *InMemorySecondaryStorage) CleanExpired() int
- func (s *InMemorySecondaryStorage) Clear()
- func (s *InMemorySecondaryStorage) Count() int
- func (s *InMemorySecondaryStorage) Delete(ctx context.Context, key string) error
- func (s *InMemorySecondaryStorage) Get(ctx context.Context, key string) (any, error)
- func (s *InMemorySecondaryStorage) GetAllKeys() []string
- func (s *InMemorySecondaryStorage) Set(ctx context.Context, key string, value string, ttlSeconds int) error
- type OAuthState
- type OAuthStateManager
- type RedisConfig
- type RedisSecondaryStorage
- func (s *RedisSecondaryStorage) Close() error
- func (s *RedisSecondaryStorage) Delete(ctx context.Context, key string) error
- func (s *RedisSecondaryStorage) Get(ctx context.Context, key string) (any, error)
- func (s *RedisSecondaryStorage) Set(ctx context.Context, key string, value string, ttlSeconds int) error
- type SecondaryStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBSecondaryStorage ¶
type DBSecondaryStorage struct {
// contains filtered or unexported fields
}
DBSecondaryStorage implements SecondaryStorage interface using GORM. It provides key-value storage with optional TTL for session data and rate limiting. This is useful as a fallback when Redis is not available.
func NewDBSecondaryStorage ¶
func NewDBSecondaryStorage(db *gorm.DB) (*DBSecondaryStorage, error)
NewDBSecondaryStorage creates a new database-backed secondary storage instance. It uses GORM for key-value storage operations.
func (*DBSecondaryStorage) Delete ¶
func (s *DBSecondaryStorage) Delete(ctx context.Context, key string) error
Delete removes the value for the given key from the database.
type InMemorySecondaryStorage ¶
type InMemorySecondaryStorage struct {
// contains filtered or unexported fields
}
InMemorySecondaryStorage implements SecondaryStorage interface using in-memory storage This is useful for testing and development without external dependencies
func NewInMemorySecondaryStorage ¶
func NewInMemorySecondaryStorage() *InMemorySecondaryStorage
NewInMemorySecondaryStorage creates a new in-memory secondary storage instance
func (*InMemorySecondaryStorage) CleanExpired ¶
func (s *InMemorySecondaryStorage) CleanExpired() int
CleanExpired removes all expired items from memory This should be called periodically by a background job
func (*InMemorySecondaryStorage) Clear ¶
func (s *InMemorySecondaryStorage) Clear()
Clear removes all items from memory (for testing purposes)
func (*InMemorySecondaryStorage) Count ¶
func (s *InMemorySecondaryStorage) Count() int
Count returns the number of items in the storage (for testing purposes)
func (*InMemorySecondaryStorage) Delete ¶
func (s *InMemorySecondaryStorage) Delete(ctx context.Context, key string) error
Delete removes the value for the given key from memory
func (*InMemorySecondaryStorage) GetAllKeys ¶
func (s *InMemorySecondaryStorage) GetAllKeys() []string
GetAllKeys returns all keys in the storage (for testing purposes)
type OAuthState ¶
type OAuthState struct {
State string `json:"state"`
ProviderID string `json:"provider_id"`
RedirectTo string `json:"redirect_to,omitempty"`
UserID string `json:"user_id,omitempty"` // For account linking
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
OAuthState represents an OAuth state parameter with metadata
type OAuthStateManager ¶
type OAuthStateManager struct {
// contains filtered or unexported fields
}
OAuthStateManager manages OAuth state parameters with CSRF protection
func NewOAuthStateManager ¶
func NewOAuthStateManager(secret string, ttl time.Duration) (*OAuthStateManager, error)
NewOAuthStateManager creates a new OAuth state manager
func (*OAuthStateManager) CleanupExpiredStates ¶
func (m *OAuthStateManager) CleanupExpiredStates() int
CleanupExpiredStates removes expired state parameters
func (*OAuthStateManager) Count ¶
func (m *OAuthStateManager) Count() int
Count returns the number of active states
func (*OAuthStateManager) GenerateState ¶
func (m *OAuthStateManager) GenerateState(providerID string, redirectTo string, userID string) (string, error)
GenerateState generates a new signed OAuth state parameter
func (*OAuthStateManager) ValidateState ¶
func (m *OAuthStateManager) ValidateState(encryptedState string) (*OAuthState, error)
ValidateState validates an encrypted OAuth state parameter
type RedisConfig ¶
type RedisConfig struct {
// Host is the Redis server host (default: "localhost")
Host string
// Port is the Redis server port (default: 6379)
Port int
// DB is the Redis database number (default: 0)
DB int
// Password is the Redis password (optional)
Password string
// TLS enables TLS connection to Redis (default: false)
TLS bool
// MaxRetries is the maximum number of retries (default: 3)
MaxRetries int
// PoolSize is the connection pool size (default: 10)
PoolSize int
}
RedisConfig holds Redis secondary storage configuration
type RedisSecondaryStorage ¶
type RedisSecondaryStorage struct {
// contains filtered or unexported fields
}
RedisSecondaryStorage implements SecondaryStorage interface using Redis. It provides key-value storage with optional TTL for session data and rate limiting.
func NewRedisSecondaryStorage ¶
func NewRedisSecondaryStorage(cfg *RedisConfig, existingClient *redis.Client) (*RedisSecondaryStorage, error)
NewRedisSecondaryStorage creates a new Redis secondary storage instance. It establishes a connection to Redis for session caching and rate limiting.
func (*RedisSecondaryStorage) Close ¶
func (s *RedisSecondaryStorage) Close() error
Close closes the Redis connection gracefully.
func (*RedisSecondaryStorage) Delete ¶
func (s *RedisSecondaryStorage) Delete(ctx context.Context, key string) error
Delete removes the value for the given key from Redis.
type SecondaryStorage ¶
type SecondaryStorage interface {
// Get retrieves the value for the given key.
Get(ctx context.Context, key string) (any, error)
// Set sets the value for the given key with optional TTL (in seconds).
Set(ctx context.Context, key string, value string, ttlSeconds int) error
// Delete removes the value for the given key.
Delete(ctx context.Context, key string) error
}
SecondaryStorage provides secondary storage for session data and rate limiting.