REST API backend in Go for browsing, uploading, downloading, managing, and searching files in a sandboxed storage root.
- Directory listing and creation
- File upload, download, preview, metadata info, and directory ZIP download
- Image thumbnails (JPEG) with caching and size controls
- Rename, move, copy, soft-delete, and restore operations
- Recursive search with filters and pagination
- JWT authentication with role-based authorization
- Security hardening: recovery, logging, CORS, rate limiting, security headers, request timeout
- Structured audit logging for write operations (who, what, when, IP, before/after)
- Go 1.26+
- Optional: Docker + Docker Compose
-
Copy environment file:
- Windows PowerShell:
Copy-Item .env.example .env - Bash:
cp .env.example .env
- Windows PowerShell:
-
Set these required values in
.env:
JWT_SECRETDATABASE_URL(example:postgresql://explorer:explorer@localhost:5432/file_explorer?sslmode=disable)
Optional pool tuning:
DB_MAX_CONNSDB_MIN_CONNS
-
Run:
go mod tidy go run ./cmd/server
Server starts on http://localhost:8080.
Health endpoint:
GET /healthOn first start, if there are no users in PostgreSQL, the service seeds a default admin user in the users table.
- Username:
admin - Password:
admin123
Change this immediately in non-test environments.
Login and use the returned access token in Authorization: Bearer <token>.
POST /api/v1/auth/loginProtected route example:
GET /api/v1/files?path=/
Authorization: Bearer <access_token>Login and capture tokens:
curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'List root directory (replace ACCESS_TOKEN):
curl -s "http://localhost:8080/api/v1/files?path=/&page=1&limit=50" \
-H "Authorization: Bearer ACCESS_TOKEN"Upload a file:
curl -s -X POST http://localhost:8080/api/v1/files/upload \
-H "Authorization: Bearer ACCESS_TOKEN" \
-F "path=/uploads" \
-F "files=@./example.txt"Search PDF files:
curl -s "http://localhost:8080/api/v1/search?q=report&path=/documents&type=file&ext=.pdf&page=1&limit=20" \
-H "Authorization: Bearer ACCESS_TOKEN"-
Auth
POST /api/v1/auth/loginPOST /api/v1/auth/register(admin)POST /api/v1/auth/refreshPOST /api/v1/auth/logoutGET /api/v1/auth/me
-
Directory + Files
GET /api/v1/filesGET /api/v1/treePOST /api/v1/directoriesPOST /api/v1/files/uploadGET /api/v1/files/downloadGET /api/v1/files/previewGET /api/v1/files/thumbnailGET /api/v1/files/info
-
Management
PUT /api/v1/files/renamePUT /api/v1/files/movePOST /api/v1/files/copyDELETE /api/v1/files(soft delete to trash)POST /api/v1/files/restoreGET /api/v1/trash(list trash records, queryinclude_restored=trueoptional)
-
Jobs (async)
POST /api/v1/jobs/operationsGET /api/v1/jobs/{job_id}GET /api/v1/jobs/{job_id}/items
-
Search
GET /api/v1/search?q=...&path=...&type=file|dir&ext=.pdf&page=1&limit=20
-
Audit
GET /api/v1/audit(admin)
-
API Docs
GET /openapi.yamlGET /swagger
Generate and serve cached thumbnails for images (JPEG output).
GET /api/v1/files/thumbnail?path=/images/photo.jpg&size=256Responses from list/search/info include thumbnail_url for supported images. Configure storage with THUMBNAIL_ROOT (default: ./state/thumbnails).
go test ./internal/... -v
go test ./test/integration/... -v -tags=integrationOr with make:
make test-allFull endpoint E2E script (requires running server):
powershell -ExecutionPolicy Bypass -File .\scripts\test-all-endpoints.ps1Or via make:
make test-endpoints- Create
.envfrom.env.example. - Run:
docker compose up --build -dData persists in:
./data(file storage)./state(thumbnails/trash state)- Docker volume
pgdata(PostgreSQL data)
Stop:
docker compose down