-
Notifications
You must be signed in to change notification settings - Fork 4
feat(sse): updated event payload and added EventReader/PingEvent #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's Guide by SourceryThis pull request introduces an Sequence diagram for Server JoinsequenceDiagram
participant HTTP Request
participant Server
participant Conn
participant Streamer
HTTP Request->>Server: Join(ctx, id, rw)
Server->>Streamer: NewStreamer(rw)
Streamer-->>Server: sm
alt Conn exists
Server->>Conn: Connect(ctx, sm)
else Conn does not exist
Server->>Conn: Create Conn(id)
Server->>Conn: Connect(ctx, sm)
end
Conn-->>Server: c
Server-->>HTTP Request: c, nil
Sequence diagram for Server BroadcastsequenceDiagram
participant Server
participant Conn
Server->>Server: Lock()
loop for each Conn
Server->>Conn: Send(event)
alt error
Conn-->>Server: error
end
end
Server->>Server: Unlock()
Updated class diagram for SSE eventsclassDiagram
class Event {
<<interface>>
Write(w io.Writer) error
}
class TextEvent {
ID string
Name string
Retry int
Data string
Write(w io.Writer) error
}
class JsonEvent {
ID string
Name string
Retry int
Data any
Write(w io.Writer) error
}
class PingEvent {
Write(w io.Writer) error
}
Event <|-- TextEvent
Event <|-- JsonEvent
Event <|-- PingEvent
Updated class diagram for Server and ConnclassDiagram
class Server {
-conns map[string]*Conn
+Join(ctx context.Context, id string, rw http.ResponseWriter) (*Conn, error)
+Leave(id string)
+Get(id string) *Conn
+Broadcast(ctx context.Context, event Event) ([]error, error)
+Shutdown()
}
class Conn {
-ID string
-s Streamer
-ctx context.Context
-cancel context.CancelFunc
+Connect(ctx context.Context, s Streamer)
+Send(event Event) error
+Wait()
+Close()
}
Server o-- Conn : contains
Class diagram for EventReaderclassDiagram
class EventReader {
-r io.Reader
+Next() (TextEvent, error)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Here's the code health analysis summary for commits Analysis Summary
|
There was a problem hiding this 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 renaming
Client
toConn
to better reflect its role as a connection rather than a client in the traditional sense. - The
EventReader
might benefit from a configurable buffer size to optimize reading from the underlyingio.Reader
.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63 +/- ##
==========================================
+ Coverage 91.09% 91.20% +0.10%
==========================================
Files 61 62 +1
Lines 2437 2535 +98
==========================================
+ Hits 2220 2312 +92
- Misses 188 192 +4
- Partials 29 31 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@sourcery-ai review |
There was a problem hiding this 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 renaming
Client
toConn
to better reflect its role as a connection rather than a client in the traditional sense. - The
bufPool
andsbPool
should probably be defined closer to where they are used.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Changed
Fixed
id
,retry
and comment support in Event's payloadAdded
EventReader
to read and parse EventPingEvent
Tests
Tasks to complete before merging PR:
make unit-tests
to check for any regressions 📋make lint
to check for any issuesSummary by Sourcery
Adds an EventReader to parse SSE events and updates the event payload to include ID, retry, and comment support.
New Features:
Tests:
Summary by Sourcery
Adds an EventReader to parse SSE events and updates the event payload to include ID, retry, and comment support.
New Features:
Tests: