This directory contains example applications demonstrating various features of the SSE package.
A minimal SSE server implementation showing:
- Basic connection setup
- Simple text message sending
- Context handling for client disconnection
- View Source
Demonstrates advanced event features:
- Custom event types
- Structured JSON data
- Heartbeat configuration
- Close message handling
- Multiple event streams
- View Source
Shows how to build a robust SSE client with:
- Proper reconnection handling
- Last-Event-ID tracking
- Server retry delay handling
- Different event type handling
- Error management
- View Source
Illustrates integration with HTTP middleware:
- Custom response writer implementation
- Request logging middleware
- Proper response writer unwrapping
- Status code tracking
- View Source
Each example can be run independently. Start the server examples with:
# Run the basic server example
go run ./1_basic_server/main.go
# Run the custom events example
go run ./2_custom_events/main.go
# Run the middleware example
go run ./4_middleware_integration/main.goFor the client example, first start one of the server examples, then in another terminal:
go run ./3_reconnection_client/main.goYou can also test the servers using curl:
# Test the basic server and middleware examples
curl -N http://localhost:8080/events
# Test the custom events example
curl -N http://localhost:8080/stocks| Example | Source | JSON Data | Custom Events | Reconnection | Middleware | Heartbeat |
|---|---|---|---|---|---|---|
| Basic Server | View | ❌ | ❌ | ❌ | ❌ | ❌ |
| Custom Events | View | ✅ | ✅ | ❌ | ❌ | ✅ |
| Reconnection Client | View | ✅ | ✅ | ✅ | ❌ | ❌ |
| Middleware Integration | View | ❌ | ❌ | ❌ | ✅ | ❌ |