This example demonstrates a simple chat application using Go Fiber and WebSockets.
This project provides a basic setup for a WebSocket-based chat application using Go Fiber. It includes the necessary configuration and code to run a real-time chat server.
main.go
: The main application entry point.home.html
: The HTML file for the chat client.go.mod
: The Go module file.
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/websocket-chat
-
Install the dependencies:
go mod download
-
Run the application:
go run main.go
The application should now be running on http://localhost:8080
.
- GET /ws: WebSocket endpoint for the chat application.
- Open your browser and navigate to
http://localhost:8080
. - Enter a message in the input field and click "Send".
- The message should appear in the chat log.
The main Go file sets up the Fiber application, handles WebSocket connections, and manages the chat hub.
The HTML file provides a simple user interface for the chat application, including a message log and input field.
This example provides a basic setup for a WebSocket-based chat application using Go Fiber. It can be extended and customized further to fit the needs of more complex applications.