A lightweight, high-performance static file server written in Go with automatic gzip compression, CORS support, and optimized for serving large files efficiently.
- 🚀 High Performance: Optimized for serving static files with minimal overhead
- 📦 Automatic Gzip Compression: Reduces bandwidth usage for compatible clients
- 🌐 CORS Support: Cross-Origin Resource Sharing enabled for all origins
- 📊 Request Logging: Built-in logging with timing information
- ⚡ Configurable Timeouts: Optimized timeout settings for large file transfers
- 🔧 Simple Configuration: Minimal setup required
- Go 1.24.4 or later
- wrk (for load testing)
- Clone the repository:
git clone <repository-url>
cd runcdn- Install dependencies:
go mod download- Build and run:
go build -o runcdn main.go
./runcdnThe server will start on http://localhost:8181 and serve files from the ./static directory.
Place your static files in the static/ directory. The server will serve them directly:
http://localhost:8181/image.jpeghttp://localhost:8181/vid.mp4http://localhost:8181/r.md
brew install wrksudo apt-get update
sudo apt-get install wrkgit clone https://github.com/wg/wrk.git
cd wrk
make
sudo cp wrk /usr/local/bin/To stress test the server with 8 threads and 1000 concurrent connections for 30 seconds:
wrk -t8 -c1000 -d30s http://127.0.0.1:8181/vid.mp4-t8: Use 8 threads-c1000: Maintain 1000 concurrent connections-d30s: Run test for 30 secondshttp://127.0.0.1:8181/vid.mp4: Target URL (replace with your file)
Based on load testing with wrk -t8 -c1000 -d30s:
- Requests/sec: 455.98
- Transfer/sec: 4.30GB
- Average Latency: 118.35ms
- Total Requests: 13,726 in 30.10s
- Data Transferred: 129.38GB
See compare.txt for detailed performance comparisons with other implementations.
The server uses the following default settings:
- Port: 8181
- Static Directory:
./static - Read Timeout: 10 seconds
- Write Timeout: 60 seconds
- Idle Timeout: 120 seconds
To modify these settings, edit the variables in main.go.
The server implements several middleware layers:
- Logging Middleware: Records request method, path, and response time
- Gzip Middleware: Automatically compresses responses when supported by client
- CORS Middleware: Enables cross-origin requests
- File Server: Serves static files from the configured directory
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.