A clean and minimal Go Fiber v3 project that demonstrates how to use Server-Sent Events (SSE) to send real-time messages to clients based on user IDs.
This project is ideal as a reusable module or reference for integrating user-targeted SSE messaging in your own applications.
- 🔄 Server-Sent Events (SSE) over HTTP
- 👤 Multiple sessions per user (
userID) - 📡 Broadcast messages to all sessions of a given user
- ✅ Graceful shutdown support
- 📊 System and runtime monitoring (
/metrics/systemendpoint) - ⚙️ Built with Go Fiber v3
Install dependencies:
go get github.com/gofiber/fiber/v3
go get github.com/shirou/gopsutil/v3git clone https://github.com/your-username/go-fiber-sse-user-channel.git
cd go-fiber-sse-user-channel
go run main.goServer will run on
http://localhost:8080
Establishes an SSE connection for the given user ID.
Example cURL:
curl -N http://localhost:8080/sse?userID=123Broadcasts a message to all active sessions of a given user.
Request Body:
{
"userID": "123",
"value": {
"message": "Hello world!"
}
}Response:
{
"sent": 2
}Basic health check endpoint.
Returns the number of open HTTP connections and active sessions.
Returns detailed system and Go runtime metrics including:
- CPU usage %
- RAM usage (used / total)
- Go memory stats
- GC cycles
- Active goroutines
- Timestamp
Useful for observability and debugging.
You can test the SSE functionality using the included example HTML file:
open examples/sse-client.htmlMake sure the Go server is running on http://localhost:8080, then open the file in your browser and enter a user ID to start receiving real-time messages.
When you press Ctrl+C or terminate the process:
- All active SSE connections are closed
- Channels are cleaned up
- The server exits cleanly within a 5-second timeout
- Real-time user notifications (e.g. order status updates)
- One-way messaging without full WebSocket complexity
- Live dashboards or system updates per user
Feel free to fork this repo or open an issue / PR if you have suggestions or improvements.
MIT — see LICENSE for details.