# Packages
# README
Go File Downloader
Overview
This project is a simple file downloader implemented in Go. It allows users to add files for download via an HTTP API and tracks the progress of each download.
Demo
Features
-
HTTP API:
- Add new files to download via a POST request.
- Retrieve the list of all files and their download statuses.
-
Progress Tracking:
- Real-time tracking of download progress, including percentage completion and estimated time remaining.
-
Concurrency:
- Utilizes goroutines to handle multiple downloads simultaneously without blocking the main application.
-
Graceful Handling of Missing Content-Length:
- Supports downloading files even when the
Content-Length
header is not provided by the server.
- Supports downloading files even when the
Topics Practiced
During the development of this project, several key topics in Go were practiced:
-
Goroutines and Concurrency:
- Implementing concurrent downloads using goroutines.
- Managing shared state safely with mutexes.
-
HTTP Server Development:
- Creating an HTTP server that handles requests and responses.
- Implementing RESTful API endpoints for adding and retrieving files.
-
JSON Encoding/Decoding:
- Working with JSON data structures for API communication.
-
File I/O Operations:
- Handling file creation and writing downloaded content to disk.
- Managing file paths using the
path
andfilepath
packages.
-
Error Handling:
- Implementing robust error handling for network requests and file operations.
-
Table Rendering in Console:
- Using external libraries (e.g.,
tablewriter
) to format and display information in the console.
- Using external libraries (e.g.,
-
Time Management:
- Utilizing the
time
package for tracking download start and finish times.
- Utilizing the
Getting Started
Prerequisites
- Go (version 1.23.1 or later)
- Internet connection for downloading files
Installation
-
Clone the repository:
git clone https://github.com/freefalI/go-file-downloader.git cd go-file-downloader
-
Build the application:
go build -o app ./src
-
Run the application:
./app
Usage
-
To add a new file for download, send a POST request to
/files/add
with a JSON body containing the URL:{ "url": "https://ash-speed.hetzner.com/100MB.bin" }
-
To retrieve the status of all downloads, send a GET request to
/files
.
Example Requests
Using curl
, you can interact with the API as follows:
-
Add a new file:
curl -X POST http://localhost:8080/files/add -d '{"url": "https://ash-speed.hetzner.com/100MB.bin"}' -H "Content-Type: application/json"
-
Get all files:
curl http://localhost:8080/files
Postman collection
License
This project is licensed under the MIT License.