This project is a Gin-based web server that can find the largest file in a directory and calculate the total size of a directory. It provides endpoints for file and directory operations. It includes structured logging using slog and environment variable management with godotenv.
Before running this application, ensure you have the following installed:
-
Go (version 1.16+)
To run the application, follow these steps:
-
go run main.go
-
The server will start and listen on the port specified in the .env file.
-
Description: Retrieves the largest file in the specified directory.
-
Parameters:
- name (path parameter): The name of the directory to search in.
-
{ "largest_file": "example.txt", "size": 1024}
-
Description: Calculates the total size of the specified directory.
-
Parameters:
- name (path parameter): The name of the directory to calculate the size of.
-
{ "total_size": 20480}
Structured logging is implemented using slog. Logs are output in JSON format and include the source file and line number of the log message. This helps in better tracing and debugging.
The application uses a custom Gin middleware for logging requests. The middleware is defined in the mid package and is used to log each incoming request to the server.
This project is licensed under the MIT License - see the LICENSE file for details.