go-serve
A simple and efficient concurrent static file server written in Go
Features
- High speed and great for concurrent request handling.
- Configurable file cache capacity to improve performance.
- Configurable logging levels (Error, Warn, Info).
- Built-in diagnostics server (pprof) accessible on port 8081.
- Serves Multiple routes for different purposes:
GET /: For serving static files. Does not require Authorization headers.
POST /: For creating new files with the payload in request body and adding them to cache. Requires Authorization headers.
PUT /: For updating existing files with the payload in request body and adding/updating them to cache. Requires Authorization headers.
DELETE /: For deleting files from disk and cache. Requires Authorization headers.
Installation
- Ensure you have Go installed on your system.
- Build the project:
Usage
You can run the server using the generated binary:
go-serve [options]
Options
-p: Set the port (default: 8000).
-d: Set the directory to serve (default: .).
-c: Set the cache entry limit (default: 64).
-l: Set the log level threshold (options: Error, Warn, Info; default: Warn).
-m: Set system rlimit on Unix systems (default: 0 [standard system rlimit]).
Example:
go-serve -p 3000 -d ./web -c 128 -l Info -m 2048
The server will start and output its address to standard error.
Logging
- Logs are outputted to standard error in the following format:
[TIMESTAMP] <METHOD> <PATH>: Status: <STATUS> | Size: <SIZE> | Time: <TIME_TAKEN>
- if an error happened while processing the request, logs include an
Error entry with the error message:
[TIMESTAMP]... | Error: <ERROR_MESSAGE>
Development
main.go: Entry point and server configuration.
handlers/: Request handler logic.
utils/: Utilities for logging, caching, and types.
sys/: Utilities that touch the system (syscalls)
See CONTRIBUTING.md for information about contributing to the project.
See CHANGELOG.md for news and changes about the project.
License
MIT License