modulepackage
0.0.0-20241205163742-7def55287cb5
Repository: https://github.com/iliyall/archive-api.git
Documentation: pkg.go.dev
# README
archive-api
Doodocs backend challenge
This project implements a REST API for managing archives and sending files via email. It follows clean code and architecture principles, ensures code extensibility. The API is built with Gin and includes testing for reliability.
Features
-
Archive Information
Extracts detailed information from an uploaded archive file.- Supported format:
.zip
- Supported format:
-
Archive Creation
Combines multiple valid files into a.zip
archive.- Supported file types:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/xml
image/jpeg
image/png
- Supported file types:
-
File Emailing
Sends an uploaded file to multiple email addresses.- Supported file types:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/pdf
- Supported file types:
Installation
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
go mod tidy
-
Configure environment variables: Create a .env file in the root directory with the following:
SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=<[email protected]> SMTP_PASSWORD=<your-email-password>
-
Run the server:
go run main.go
Endpoints and cURL Examples
1. Get Archive Information
- URL:
/api/archive/information
- Method:
POST
- Content-Type:
multipart/form-data
cURL Example:
curl -X POST http://localhost:8080/api/archive/information \
-H "Content-Type: multipart/form-data" \
-F "file=@my_archive.zip" \
-w "\nHTTP Status Code: %{http_code}\n"
Response:
{
"filename": "my_archive.zip",
"archive_size": 4102029.312,
"total_size": 6836715.52,
"total_files": 2,
"files": [
{
"file_path": "photo.jpg",
"size": 2516582.4,
"mimetype": "image/jpeg"
},
{
"file_path": "directory/document.docx",
"size": 4320133.12,
"mimetype": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
]
}
- Create Archive
- URL:
/api/archive/files
- Method:
POST
- Content-Type:
multipart/form-data
cURL Example:
curl -X POST http://localhost:8080/api/archive/files \
-H "Content-Type: multipart/form-data" \
-F "files[][email protected]" \
-F "files[][email protected]" \
-w "\nHTTP Status Code: %{http_code}\n"
Response:
Returns the .zip archive as binary data.
To save the output as a .zip file:
curl -X POST http://localhost:8080/api/archive/files \
-H "Content-Type: multipart/form-data" \
-F "files[][email protected]" \
-F "files[][email protected]" \
-w "\nHTTP Status Code: %{http_code}\n" \
--output your_archive.zip
- Send File via Email
- URL:
/api/mail/file
- Method:
POST
- Content-Type:
multipart/form-data
cURL Example:
curl -X POST http://localhost:8080/api/mail/file \
-H "Content-Type: multipart/form-data" \
-F "[email protected]" \
-F "[email protected],[email protected],[email protected]" \
-w "\nHTTP Status Code: %{http_code}\n"