A web application for testing Server-Sent Events (SSE) protocol using Golang
2.3K
A web application for testing and demonstrating the Server-Sent Events (SSE) protocol using Golang.
Server-Sent Events (SSE) is a lightweight, unidirectional protocol for streaming real-time text data from a server to a client over a single, long-lived HTTP connection. Using the text/event-stream format, it enables efficient server-to-browser updates (e.g., dashboards, notifications) with built-in auto-reconnection.
References:
It implements a Backend in Go serving a Frontend, Prometheus metrics, and Docker configurations.
The application follows a clean, modular architecture:
/sse endpoint that streams Server-Sent Events with proper headers and persistent connections.The application correctly implements the Server-Sent Events specification with:
Cache-Control: no-cache header sethttp.Flusher interfaceContent-Type: text/event-streamConnection: keep-aliveHTTP/1.1 200 OK| Endpoint | Method | Description |
|---|---|---|
/ | GET | Frontend HTML interface |
/sse | GET | Server-Sent Events stream |
/health | GET | Health check endpoint |
/metrics | GET | Prometheus metrics endpoint |
/static/* | GET | Static assets (CSS, JavaScript) |
The application exposes the following Prometheus metrics:
sse_http_requests_total - Total HTTP requests by path and methodsse_active_connections - Number of active SSE connectionssse_events_sent_total - Total events sent via SSE endpointsse_event_duration_seconds - Event processing duration histogramcd app
# Using Docker Compose (includes Prometheus and Grafana)
docker-compose up -d
# Check logs
docker-compose logs -f go-sse
# Open the application
# Frontend: http://localhost:8080
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (admin / admin)
# Stop services
docker-compose down


docker build -t aeciopires/go-sse:1.0.0 .
docker run -d -p 8080:8080 --name go-sse aeciopires/go-sse:1.0.0
docker logs -f go-sse
docker stop go-sse
cd app
go mod download
go mod tidy
go run main.go
Open your browser and navigate to http://localhost:8080
The application will:
//sse/metrics/healthcd app
# Build the binary
make build
# Build and run Docker image
make up
# View logs
make logs
# Stop the container
make down
# Recreate container
make recreate
To build a Docker image with multi-platform support:
cd app
# Build for multiple platforms and push to Docker Hub
make image
# You will be prompted for:
# - Docker Hub username
# - Docker Hub password
The command will build and push images for:
linux/amd64linux/arm/v6linux/arm/v7linux/arm64See the CONTRIBUTING.md file for development guidelines and instructions on how to contribute to this project.
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Content type
Image
Digest
sha256:6679f7830…
Size
11.5 MB
Last updated
7 months ago
docker pull aeciopires/go-sse