This repository contains a simple Golang application demonstrating how to implement Server-Sent Events (SSE) without using any web frameworks. SSE enables real-time updates from the server to the client without continuous polling.
- Provides a basic HTML page with a button that triggers SSE events when clicked.
- Sends server-generated events to connected clients when the button is clicked.
- Demonstrates SSE communication using vanilla Go HTTP.
- Clone the repository:
git clone https://github.com/phuongdanh/golang-sse.git
- Navigate to the repository directory:
cd golang-sse
- Run the application:
go run main.go
- Access the application in your browser at
http://localhost:8080
.
- When you access the application in your browser, you'll see a button labeled "Send Event".
- Clicking the button triggers a POST request to the server, which sends an SSE event with a timestamp to all connected clients.
- The client-side JavaScript establishes an SSE connection to the server and displays the received events in real-time.
- Go (Golang) must be installed on your system.
This project is licensed under the MIT License.
Feel free to use this example to learn about SSE implementation or as a starting point for your own SSE-based projects.
If you find this example useful, consider giving it a ⭐️ on GitHub!