This is a file sharing backend system implemented using Go, GORM, and Redis. It supports file uploads, retrieval, sharing, deletion, and search functionality. It also includes rate limiting and caching with Redis.
To get started with the project, follow these steps:
-
Clone the Repository:
git clone https://github.com/Sovan22/21BPS1465_Backend.git cd 21BPS1465_Backend
-
Install Dependencies: Ensure you have Go and Redis installed. Then, run:
go mod tidy
-
If not using Docker Remove comment
os.Setenv("REDIS_URL", "localhost:6379")
in func main of main.go -
Run the Server:
go run main.go
To run the project using Docker and Docker Compose, follow these steps:
-
Ensure Docker and Docker Compose are installed.
-
Clone the Repository
git clone https://github.com/Sovan22/21BPS1465_Backend.git cd 21BPS1465_Backend
-
Build and Run Docker Containers:
docker-compose up --build
-
Access the Application: The application will be available at
http://localhost:8080
.
- Register a New User
- Endpoint:
POST /register
- Description: Registers a new user.
- Request Body:
{ "email": "user@example.com", "password": "password123" }
- Responses:
200 OK
- Registration successful.400 Bad Request
- Invalid input or email already registered.500 Internal Server Error
- Server error.
- Endpoint:
- Login
- Endpoint:
POST /login
- Description: Logs in a user and returns a JWT token.
- Request Body:
{ "email": "user@example.com", "password": "password123" }
- Responses:
200 OK
- Login successful with token.401 Unauthorized
- Invalid credentials.500 Internal Server Error
- Server error.
- Endpoint:
-
Upload File
-
Get User Files
-
Share File
- Endpoint:
GET /share/:fileID
- Description: Generates a shareable link for a file.
- Query Parameters:
fileID
- ID of the file to share.expiry
- Expiry time for the shareable link (optional) "1h", "30m" ,"1h30m".
- Responses:
- Endpoint:
-
Delete File
-
Search Files
- Endpoint:
GET /search
- Description: Searches for files based on name, type, and uploaded date.
- Query Parameters:
name
- Partial name of the file.type
- Type of the file (e.g., pdf).date
- Uploaded date in format YYYY-MM-DD.limit
- Number of results to return (optional).offset
- Pagination offset (optional).
- Responses:
- Endpoint:
To prevent abuse, the API enforces rate limiting:
- Limit: 100 requests per user per minute.
- File Metadata Caching: Cached using Redis to reduce database load. The cache expires after 5 minutes.