GodocAPI is a high-performance, Go-based RESTful API service designed for managing documents. It leverages the Fiber framework for HTTP handling, PostgreSQL for metadata storage, and RustFS (S3-compatible) for object storage.
- Document Management: Upload, download, list, and delete documents.
- High Performance: Built with Go 1.22 and Fiber v2.
- Metadata Storage: Reliable metadata management using PostgreSQL.
- Object Storage: Scalable file storage using RustFS (via AWS SDK for Go).
- Docker Ready: Includes Dockerfile for easy containerization.
- Language: Go 1.22
- Framework: Fiber v2
- Database: PostgreSQL (pgx driver)
- Storage: RustFS (S3 Compatible)
- Config: godotenv
- Go 1.22+
- PostgreSQL 14+
- RustFS (or any S3-compatible storage like MinIO)
Duplicate the .env file or set environment variables:
SERVER_PORT=:8080
DB_URL=postgres://user:password@localhost:5432/godocapi?sslmode=disable
RUSTFS_ENDPOINT=http://localhost:9000
RUSTFS_ACCESS_KEY=your_access_key
RUSTFS_SECRET_KEY=your_secret_key
RUSTFS_BUCKET=documents
RUSTFS_REGION=us-east-1The easiest way to set up PostgreSQL and RustFS locally is using Docker Compose.
-
Start dependencies:
docker-compose up -d
This will start:
- PostgreSQL on port
5432 - RustFS (Object Storage) on port
9000(Console:9001) - It will also automatically create the
documentsbucket.
- PostgreSQL on port
-
Initialize Database Schema: Use a tool like DBeaver or
psqlto run the following DDL:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS documents (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
filename TEXT NOT NULL,
storage_path TEXT NOT NULL UNIQUE,
size BIGINT NOT NULL CHECK (size >= 0),
content_type TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_documents_filename ON documents (filename);- Install dependencies:
go mod tidy
- Run the application:
go run cmd/api/main.go
- Build the image:
docker build -t godocapi . - Run the container:
docker run -p 8080:8080 --env-file .env godocapi
To start the full application stack (Frontend + Backend):
docker-compose up --buildThe services will be available at:
- Frontend: http://localhost:3000
- Backend: http://localhost:8080
-
Initialize Swarm (if not already initialized):
docker swarm init
-
Deploy the Stack:
docker stack deploy -c docker-stack.yml godocapi
-
Verify Services:
docker service ls
The API documentation is auto-generated using Swagger. After running the application, you can access the Swagger UI at:
http://localhost:8080/swagger/index.html
GET /api/v1/health- Check if the service is running.
POST /api/v1/documents- Upload a new document (Multipart Form:
file).
- Upload a new document (Multipart Form:
GET /api/v1/documents- List all documents.
GET /api/v1/documents/:id- Get document metadata.
GET /api/v1/documents/:id/download- Download the document file.
DELETE /api/v1/documents/:id- Delete a document.