A secure TLS echo server written in Go that demonstrates advanced networking concepts, including:
- TLS Encryption: All client-server communications are encrypted using TLS.
- Connection Limiting: Enforces a maximum number of concurrent connections using channels and mutexes.
- Prometheus Metrics: Exposes runtime metrics (total connections and active connections) on a dedicated HTTP endpoint for monitoring.
- Graceful Shutdown: Handles system signals to gracefully shut down the server.
- Rate Limiting: Prevents the server from being overwhelmed by too many requests.
- Basic Authentication: Restricts access to the server using username and password.
- Go 1.16 or later
- Prometheus (if you wish to scrape the metrics)
-
Clone the Repository:
cd go-tls-echo-server -
Build the Server:
go build -o echo-server
Run the server with default parameters:
./echo-serverYou can also specify flags:
./echo-server -port=20080 -bufferSize=512 -certFile=server.crt -keyFile=server.key -maxConn=100 -rateLimit=10 -metricsAddr=":9090"The server exposes Prometheus metrics on the /metrics endpoint (by default at http://localhost:9090/metrics). Monitor total connections and active connections in real time.
The server listens for SIGINT and SIGTERM signals. Use Ctrl+C to gracefully shut down the server.
Run the test cases with:
go test -vThis will execute the provided test for the echo functionality, ensuring the server echoes messages correctly.