Compare commits

...

5 Commits
v0.0.4 ... main

Author SHA1 Message Date
savinmax
f69355d69d small fix
All checks were successful
CI / test (push) Successful in 10s
CI / lint (push) Successful in 11s
2025-08-04 11:11:10 +02:00
savinmax
9ad38190a5 adding config-file arg
All checks were successful
Release / release (push) Successful in 19s
CI / test (push) Successful in 9s
CI / lint (push) Successful in 12s
2025-08-02 21:31:35 +02:00
savinmax
983c4195e0 Metrics config example
All checks were successful
CI / test (push) Successful in 9s
CI / lint (push) Successful in 11s
2025-08-02 21:07:26 +02:00
savinmax
e4abd6e0a7 fix release
All checks were successful
Release / release (push) Successful in 14s
2025-08-02 21:00:28 +02:00
savinmax
ef3539fd31 Publishing release
All checks were successful
Release / release (push) Successful in 15s
2025-08-02 19:36:14 +02:00
5 changed files with 39 additions and 19 deletions

View File

@ -20,9 +20,20 @@ jobs:
run: VERSION=${{ github.ref_name }} make release
- name: Upload Release Assets
id: upload-release-assets
uses: https://gitea.com/actions/gitea-upload-artifact@main
with:
name: websocket-relay
path: build/*
overwrite: true
- name: Create Release
uses: akkuman/gitea-release-action@v1
env:
NODE_TLS_REJECT_UNAUTHORIZED: false
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: |-
build/*

View File

@ -7,7 +7,7 @@ A minimal Go WebSocket relay server with SSL support for P2P connections.
```bash
go mod tidy
# Configure via config.yaml (see config.yaml for options)
go run main.go
go run main.go --config-file=./config.yaml
```
## Configuration
@ -18,16 +18,16 @@ Edit `config.yaml` to configure:
## Usage
- WebSocket endpoint: `/ws`
- WebSocket endpoint: `/`
- All WebSocket messages are relayed to all connected clients
## Testing
```javascript
// For TLS enabled (default config)
const ws = new WebSocket('wss://localhost:8443/ws');
const ws = new WebSocket('wss://localhost:8443/');
// For HTTP only
// const ws = new WebSocket('ws://localhost:8443/ws');
// const ws = new WebSocket('ws://localhost:8443/');
ws.onmessage = (event) => console.log('Received:', event.data);
ws.send('Hello from client!');
```

View File

@ -3,4 +3,8 @@ server:
tls:
enabled: true
cert_file: cert.pem
key_file: key.pem
key_file: key.pem
metrics:
enabled: true
port: 9090

View File

@ -11,18 +11,18 @@ var (
Help: "Number of currently connected WebSocket clients",
})
MessagesTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "websocket_messages_total",
Help: "Total number of WebSocket messages processed",
MessagesTotal = promauto.NewGauge(prometheus.GaugeOpts{
Name: "websocket_message",
Help: "Number of WebSocket messages processed",
})
ConnectionsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "websocket_connections_total",
Help: "Total number of WebSocket connections established",
ConnectionsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Name: "websocket_connection",
Help: "Number of WebSocket connections established",
})
DisconnectionsTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "websocket_disconnections_total",
Help: "Total number of WebSocket disconnections",
DisconnectionsTotal = promauto.NewGauge(prometheus.GaugeOpts{
Name: "websocket_disconnection",
Help: "Number of WebSocket disconnections",
})
)
)

11
main.go
View File

@ -1,17 +1,22 @@
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"websocket-relay/internal/config"
"websocket-relay/internal/hub"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
cfg, err := config.Load("config.yaml")
configFile := flag.String("config-file", "config.yaml", "Path to configuration file")
flag.Parse()
cfg, err := config.Load(*configFile)
if err != nil {
log.Fatal("Failed to load config:", err)
}
@ -30,7 +35,7 @@ func main() {
}
mux := http.NewServeMux()
mux.HandleFunc("/ws", h.HandleWebSocket)
mux.HandleFunc("/", h.HandleWebSocket)
addr := fmt.Sprintf(":%d", cfg.Server.Port)
if cfg.Server.TLS.Enabled {