Skip to content

bigDataByChirag/file-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Analysis

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.

Prerequisites

Before running this application, ensure you have the following installed:

  1. Go (version 1.16+)

  2. Git

  3. Go Modules

Running the Application

To run the application, follow these steps:

  1. go run main.go

  2. The server will start and listen on the port specified in the .env file.

Endpoints

GET /file/

  • Description: Retrieves the largest file in the specified directory.

  • Parameters:

    • name (path parameter): The name of the directory to search in.
  • curl http://localhost:8080/file/example\_directory

  • { "largest_file": "example.txt", "size": 1024}

GET /dir/

  • Description: Calculates the total size of the specified directory.

  • Parameters:

    • name (path parameter): The name of the directory to calculate the size of.
  • curl http://localhost:8080/dir/example\_directory

  • { "total_size": 20480}

Logging

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.

Middleware

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages