A zero-complexity pub/sub WebSocket server built for smaller projects and rapid prototyping. Spin up instantly, deploy with ease, and focus on your application logic, not infrastructure.
gosocket is designed for developers who need to add real-time capabilities to smaller apps, prototypes, or MVPs in minutes. It avoids the overhead of complex message brokers by providing a single, focused binary that handles rooms and message broadcasting out of the box.
Install gosocket using Go:
go install github.com/awoldt/gosocket@latest
Or clone and build from source:
git clone https://github.com/awoldt/gosocket.git
cd gosocket
go build -o gosocket .
Designed for developers who need a reliable WebSocket layer without the overhead of complex message brokers.
Start the WebSocket server:
gosocket start
On first run, a config.yaml file is automatically created with default settings. The server
listens on port 8080 by default.
Configure your server by editing config.yaml:
# config.yaml
allowed_origins: [] # Empty allows all origins
read_buffer_size: 1024
write_buffer_size: 1024
port: "8080"
auth_token: "" # Set a token to require authentication
| Option | Description | Default |
|---|---|---|
| allowed_origins | List of allowed origins for CORS. Empty array allows all. | [] |
| read_buffer_size | WebSocket read buffer size in bytes. | 1024 |
| write_buffer_size | WebSocket write buffer size in bytes. | 1024 |
| port | Port the server listens on. | "8080" |
| auth_token | Optional token for authentication. Empty disables auth. | "" |
Clients connect to rooms via the URL path. The path becomes the room name:
// Connect to the "chat" room
ws://localhost:8080/chat
// Connect to the "notifications" room
ws://localhost:8080/notifications
// Connect with authentication token
ws://localhost:8080/chat?token=your-secret-token
// Connect to a room
const ws = new WebSocket('ws://localhost:8080/chat');
ws.onopen = () => {
console.log('Connected to chat room');
ws.send('Hello, room!');
};
ws.onmessage = (event) => {
console.log('Received:', event.data);
};
ws.onclose = () => {
console.log('Disconnected');
};
gosocket uses a simple pub/sub model:
/chat)
To enable authentication, set the auth_token in your config:
auth_token: "my-secret-token"
Clients must then include the token as a query parameter:
ws://localhost:8080/chat?token=my-secret-token
Connections without a valid token will receive a 401 Unauthorized response.