Documentation
¶
Index ¶
- Variables
- type PostgresService
- func (s *PostgresService) GetOrCreateUser(ctx context.Context, whoopUserID int64) (string, bool, error)
- func (s *PostgresService) IsBanned(ctx context.Context, whoopUserID int64) (bool, error)
- func (s *PostgresService) UpdateAPIKeyLastUsed(ctx context.Context, apiKeyID int64) error
- func (s *PostgresService) ValidateAPIKey(ctx context.Context, apiKey string) (*ValidatedUser, error)
- type Service
- type ValidatedUser
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type PostgresService ¶
type PostgresService struct {
// contains filtered or unexported fields
}
func NewPostgresService ¶
func NewPostgresService(db pgc.Querier) *PostgresService
func (*PostgresService) GetOrCreateUser ¶
func (*PostgresService) UpdateAPIKeyLastUsed ¶
func (s *PostgresService) UpdateAPIKeyLastUsed(ctx context.Context, apiKeyID int64) error
func (*PostgresService) ValidateAPIKey ¶
func (s *PostgresService) ValidateAPIKey(ctx context.Context, apiKey string) (*ValidatedUser, error)
type Service ¶
type Service interface {
// ValidateAPIKey validates an API key and returns the associated user info.
// Returns ErrAPIKeyNotFound if the key doesn't exist,
// ErrAPIKeyRevoked if the key has been revoked,
// or ErrUserBanned if the user account is banned.
ValidateAPIKey(ctx context.Context, apiKey string) (*ValidatedUser, error)
// GetOrCreateUser retrieves an existing user or creates a new one.
// Always generates and returns a new API key for non-banned users.
// For existing users, all previous API keys are revoked.
GetOrCreateUser(ctx context.Context, whoopUserID int64) (apiKey string, banned bool, err error)
// UpdateAPIKeyLastUsed updates the last_used_at timestamp for an API key.
// This is typically called asynchronously after successful validation.
UpdateAPIKeyLastUsed(ctx context.Context, apiKeyID int64) error
// IsBanned checks if a user is banned.
IsBanned(ctx context.Context, whoopUserID int64) (bool, error)
}
type ValidatedUser ¶
Click to show internal directories.
Click to hide internal directories.