Demo implementation of Server-Sent Events (SSE) in Golang.
Server-Sent Events (SSE) is a server push technology enabling a client to receive automatic updates from a server via an HTTP connection. This project is a demo implementation of SSE in Golang, showcasing how to build a simple SSE server and client.
- Real-time Updates: Push notifications to clients in real-time.
- Simple Implementation: Easy to understand and extend.
- Golang: Utilizes the powerful and efficient Go programming language.
Before you begin, ensure you have met the following requirements:
- Go (Golang) installed on your machine. You can download it from golang.org.
- Basic understanding of Golang and SSE concepts.
Follow these steps to set up and run the project:
-
Clone the repository:
git clone https://github.com/maen08/sse-on-golang.git cd sse-on-golang
-
Install dependencies:
go mod tidy
-
Build the project:
go build -o sse-server main.go
-
Run the server:
./sse-server
To use the SSE server, follow these steps:
- Start the SSE server (as shown in the installation section).
- Open a web browser or an HTTP client and navigate to
http://localhost:8080/events
. - The client will automatically receive updates from the server.
The project consists of the following components:
- Server: Handles client connections and sends events.
- Client: Listens for events from the server and processes them.
- Event Handler: Manages the creation and broadcasting of events to connected clients.
Here is an example of how to use the SSE server:
-
Start the server:
./sse-server
-
Open a web browser and navigate to
http://localhost:8080/events
. -
The server will send real-time updates to the client, which will be displayed in the browser.
We welcome contributions! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes and commit them (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a pull request.
Please ensure your code adheres to the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License. See the LICENSE file for more information.