⚠️ Disclaimer: This project is currently unstable and undergoing active development and testing.
GoDispatch is a high-performance WebSocket engine built in Go that replaces custom real-time backend code with a simple, declarative YAML configuration. Define your event logic, security rules, and message routing in config.yaml, and let the engine handle the rest.
- Declarative Logic: Define your application's real-time behavior (events, actions, security) in a
config.yamlfile instead of writing Go code. - Secure by Design: Built-in support for JWT-based authentication for sessions and events.
- Stateful Modifiers: Implement complex validation logic like rate limiting with ease.
- Extensible: Add new custom "actions" and "modifiers" in Go to extend the engine's core functionality.
- Go (version 1.22 or later)
git clone https://github.com/a-essam23/go-dispatch.git
cd go-dispatchGoDispatch uses a .env file for local development to manage secrets.
Copy the example environment file:
cp .env.example .envThe default .env file contains the secret key (a-very-secret-key-from-env-file) that matches the config.yaml.
You can run the server directly or using the Makefile.
With make (Recommended):
make runWithout make:
go run ./cmd/go-dispatch/main.goYou should see log output indicating the server has started on :8080.
{"time":"...","level":"INFO","msg":"Server starting","addr":":8080"}
Now you can connect to the server with any WebSocket client. Here's how to do it with your browser's developer console.
Step A: Generate a Session Token
GoDispatch requires a valid JWT for the initial connection.
- Go to jwt.io.
- Change the algorithm to
HS256. - Set the payload to include a
sub(Subject/UserID) claim:{ "sub": "user-123", "name": "Test User" } - In the "Verify Signature" section, paste the secret from your
.envfile:a-very-secret-key-from-env-file. - Copy the entire encoded token (the long string in the left panel).
Step B: Connect via Browser Console
Open a blank page in your browser, open the developer console (F12), and paste this JavaScript code. Replace <YOUR_SESSION_TOKEN> with the token you just generated.
const sessionToken = "<YOUR_SESSION_TOKEN>";
const ws = new WebSocket("ws://localhost:8080/ws", ["Authorization", `Bearer ${sessionToken}`]);
ws.onopen = () => {
console.log("✅ WebSocket connection established!");
// Example 1: Send a simple message to a room
const message = {
event: "send_message_to_room",
target: "room-lobby",
payload: {
message: "Hello from the browser!"
}
};
ws.send(JSON.stringify(message));
console.log("Sent message:", message);
// Example 2: Trigger a rate-limited event (try this multiple times quickly)
// See config.yaml for the 'send_message_rate_limited' event
};
ws.onmessage = (event) => {
console.log("⬅️ Received from server:", JSON.parse(event.data));
};
ws.onclose = (event) => {
console.error("❌ WebSocket connection closed:", event);
};
ws.onerror = (error) => {
console.error("💥 WebSocket error:", error);
};You have now successfully connected to and interacted with your GoDispatch server!
- Configuration: Learn how to customize the server's behavior in the Configuration Guide (CONFIG.md).
- Architecture: Understand the internal design by reading the Architecture Guide (ARCHITECTURE.md).
Contributions are welcome! Please feel free to open an issue or submit a pull request.