You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 1. Install dependencies
go mod tidy
# 2. Configure environment
cp .env.example .env
# Edit .env to match your setup# 3. Initialize database
mysql -u root -p gofile < schema.sql
# 4. Run
go run main.go
Or use startup scripts (loads .env automatically):
./start.sh # Start with .env
./start.sh --migrate # Run schema.sql then start
./start.sh --build # Build binary then run
Windows:
start.bat # Start with .env
start.bat --migrate # Run schema.sql then start
start.bat --build # Build binary then run
⚙️ Configuration
Variable
Default
Description
SERVER_ADDR
:8080
HTTP listen address
MYSQL_DSN
root:root@tcp(127.0.0.1:3306)/gofile?...
MySQL connection string
UPLOAD_DIR
./uploads
Local storage directory (fallback)
CHUNK_DIR
./chunks
Chunk temp directory
MINIO_ENDPOINT
minio:9000
MinIO endpoint (empty = skip MinIO)
MINIO_ACCESS_KEY
minioadmin
MinIO access key
MINIO_SECRET_KEY
minioadmin
MinIO secret key
MINIO_BUCKET
filestore
MinIO bucket name
MINIO_USE_SSL
false
Enable SSL for MinIO
💡 The server attempts MinIO first. If MINIO_ENDPOINT is empty or MinIO init fails, it falls back to local storage at UPLOAD_DIR.
📡 API Endpoints
File Operations (Auth Required)
Method
Route
Description
POST
/file/upload
Upload file (supports instant dedup)
GET
/file/meta
Get file metadata by hash
GET
/file/query
List all files for current user
GET
/file/download
Download file by hash
POST
/file/update
Rename file
POST
/file/delete
Soft delete file
Chunked Upload (Auth Required)
Method
Route
Description
POST
/file/upload/chunk
Upload a single chunk (idempotent)
GET
/file/upload/status
Check uploaded chunk indices
POST
/file/upload/merge
Merge chunks into final file
User Operations
Method
Route
Auth
Rate Limit
Description
POST
/user/signup
×
✓
Register
POST
/user/signin
×
✓
Login, get token (HttpOnly Cookie)
GET
/user/info
✓
×
Get user info
System
Method
Route
Description
GET
/healthz
Health check
GET
/static/*
Static frontend pages
💻 Usage Examples
# Register
curl -X POST -d "username=test&password=123456" http://localhost:8080/user/signup
# Login (cookie stored locally, auto-sent on subsequent requests)
curl -X POST -F "username=test&password=123456" http://localhost:8080/user/signin -c cookies.txt
# Upload a file
curl -X POST -F "file=@./test.txt" -b cookies.txt \
http://localhost:8080/file/upload
# Download a file
curl -b cookies.txt \
"http://localhost:8080/file/download?filehash=HASH" -o output.txt
🧪 Testing
go test ./... # Run all tests
go test -v ./handler/ # Handler tests with verbose output
go test ./util/ # Util tests only