This is a Go-based image server that converts and serves images in WebP format. It provides caching capabilities and supports runtime configuration through a JSON file.
- Converts JPEG and PNG images to WebP format on-the-fly
- Caches converted images for improved performance
- Configurable quality and server settings for WebP conversion
- Cache clearing functionality with key-based authentication
- Debug logging for easier troubleshooting
- Go 1.16 or higher
-
Clone the repository:
git clone https://github.com/yourusername/configurable-image-server.git cd configurable-image-server
-
Build the project:
make
Create a config.json
file in the project root directory with the following structure:
{
"quality": 90,
"cacheFolder": "./cache",
"cacheClearKey": "yourSecretKey",
"port": "8080",
"debug": true
}
quality
: WebP conversion quality (0-100)cacheFolder
: Directory to store cached WebP imagescacheClearKey
: Secret key for cache clearing functionalityport
: Port number for the server to listen ondebug
: Enable or disable debug logging
-
Start the server:
go run main.go -config config.json
-
Access images through the server:
http://localhost:8080/path/to/your/image.jpg
The server will convert the image to WebP format, cache it, and serve it.
-
Clear the cache:
http://localhost:8080/clearcache?key=yourSecretKey
Replace
yourSecretKey
with the value specified in yourconfig.json
.
When debugLogging
is set to true
in the configuration, the server will output detailed log messages to help with troubleshooting and monitoring. These messages include information about request handling, file operations, and cache management.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the AGPLv3 License - see the LICENSE file for details.