package storage import ( "context" "database/sql" "errors" "fmt" ) const googleSignInRead = ` SELECT l.user_id, u.disabled, u.credentials_epoch FROM google_links l JOIN users u ON u.id = l.user_id WHERE l.google_sub = ?` type GoogleSignIn struct { UserID string Disabled bool CredentialsEpoch int64 } func (s *Store) LookupGoogleSignIn(ctx context.Context, googleSub string) (GoogleSignIn, error) { const operation = "lookup google sign-in" if err := s.checkOpen(operation); err != nil { return GoogleSignIn{}, err } if err := requireValue("google subject", googleSub); err != nil { return GoogleSignIn{}, invalid(operation, err) } var g GoogleSignIn var disabled int err := s.sql.QueryRowContext(ctx, googleSignInRead, googleSub).Scan(&g.UserID, &disabled, &g.CredentialsEpoch) if errors.Is(err, sql.ErrNoRows) { return GoogleSignIn{}, fmt.Errorf("%s: %w", operation, ErrNotFound) } if err != nil { return GoogleSignIn{}, classify(operation, err) } g.Disabled = disabled != 0 return g, nil }