Skip to content

Conversation

cnlangzi
Copy link
Member

@cnlangzi cnlangzi commented Feb 26, 2025

Changed

Fixed

Added

  • feat(sse): added ext/sse

Tests

Tasks to complete before merging PR:

  • Ensure unit tests are passing. If not run make unit-test to check for any regressions 📋
  • Ensure lint tests are passing. if not run make lint to check for any issues
  • Ensure codecov/patch is passing for changes.

Summary by Sourcery

Introduce ext/sse package for server-sent events (SSE) functionality.

New Features:

  • Introduce ext/sse package for server-sent events (SSE) functionality, including Server, Client, Event, and Streamer interfaces.

CI:

  • Update Go version in CI workflow to 1.24.0 and golangci-lint-action to v1.64.5.

Tests:

  • Add unit tests for the new SSE server implementation.

Copy link

sourcery-ai bot commented Feb 26, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ext/sse package, which provides server-sent events (SSE) functionality. It includes a Server to manage clients, a Client to handle connections, and an Event to transmit data. The changes also update the Go version and linter version in the CI workflow.

Sequence diagram for joining a client to the SSE server

sequenceDiagram
  participant Client
  participant Server
  participant Streamer

  Client->>Server: Join(ctx, id, streamer)
  Server->>Server: Lock()
  Server->>Server: Check if client exists
  alt Client exists
    Server->>Client: Get existing client
  else Client does not exist
    Server->>Client: Create new client
    Server->>Server: Store client
  end
  Server->>Client: Connect(ctx, streamer)
  Client->>Streamer: Assign streamer
  Server->>Streamer: Header().Set("Content-Type", "text/event-stream")
  Server->>Streamer: Header().Set("Cache-Control", "no-cache")
  Server->>Streamer: Header().Set("Connection", "keep-alive")
  Server->>Server: Unlock()
  Server-->>Client: Return client
Loading

Sequence diagram for broadcasting an event to all connected clients

sequenceDiagram
  participant Server
  participant Client1
  participant Client2

  Server->>Server: RLock()
  Server->>Server: Iterate through clients
  loop For each client
    Server->>Client1: Send(event)
    Server->>Client2: Send(event)
  end
  Server->>Server: RUnlock()
  Client1->>Client1: Marshal event data to JSON
  Client1->>Streamer: Write event name and data
  Client1->>Streamer: Flush()
  Client2->>Client2: Marshal event data to JSON
  Client2->>Streamer: Write event name and data
  Client2->>Streamer: Flush()
Loading

File-Level Changes

Change Details Files
Introduces the ext/sse package, providing functionality for server-sent events (SSE).
  • Adds Server struct to manage clients.
  • Adds Client struct to handle connections.
  • Adds Event struct to transmit data.
  • Adds methods to Server for joining, leaving, getting clients, and broadcasting events.
  • Implements Client methods to connect to a streamer and send events.
ext/sse/server_test.go
ext/sse/server.go
ext/sse/client.go
ext/sse/streamer.go
ext/sse/event.go
Updates the Go version and golangci-lint version in the CI workflow.
  • Updates Go version to 1.24.0.
  • Updates golangci-lint to v1.64.5.
.github/workflows/tests.yml
go.mod

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

deepsource-io bot commented Feb 26, 2025

Here's the code health analysis summary for commits 573f3f1..ad9420d. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Go LogoGo✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cnlangzi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding an example usage to the package documentation.
  • The Wait method on the Client struct doesn't seem to do anything other than block until the context is done - is this intentional?
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.81%. Comparing base (573f3f1) to head (ad9420d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #59      +/-   ##
==========================================
- Coverage   94.27%   90.81%   -3.46%     
==========================================
  Files          56       58       +2     
  Lines        2305     2363      +58     
==========================================
- Hits         2173     2146      -27     
- Misses         98      188      +90     
+ Partials       34       29       -5     
Flag Coverage Δ
Unit-Tests 90.81% <100.00%> (-3.46%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cnlangzi
Copy link
Member Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cnlangzi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding an example usage to the package documentation.
  • The Client.Connect method doesn't seem to do much - is it really needed?
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cnlangzi
Copy link
Member Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cnlangzi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding an example of how to use the SSE server in a README or example file.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@cnlangzi cnlangzi merged commit ac40b61 into main Feb 26, 2025
7 of 8 checks passed
@cnlangzi cnlangzi deleted the fix/htmx_sse branch February 26, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant