Thanks to visit codestin.com
Credit goes to github.com

Skip to content

electr1fy0/flux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flux

Lightweight concurrent file server with one-time authentication codes.

Quick Start

go get github.com/go-chi/chi/v5
go run main.go

Server runs on :8080. Creates ./uploads on startup.

Authentication

Pass codes via X-Upload-Code header. Each code works once - any request (even failed ones) burns it.

Default codes: 123, 456, 789

API

POST /upload
Body: multipart/form-data with file field
Response: {"body": "file successfully uploaded"}

GET /files
Response: Plain text list of filenames (one per line)

GET /files/{filename}
Response: File download (binary)

Limits: 50MB max upload, 30s timeout per request

Examples

# Upload
curl -H "X-Upload-Code: 123" \
     -F "[email protected]" \
     http://localhost:8080/upload

# List files
curl -H "X-Upload-Code: 456" \
     http://localhost:8080/files

# Download
curl -H "X-Upload-Code: 789" \
     -O http://localhost:8080/files/data.json

Architecture

Middleware chain:

  1. OneTimeCodeAuth - validates and consumes code (mutex-protected, runs on ALL routes)
  2. RequestID - traces each request
  3. Timeout - enforces 30s deadline
  4. LogWithRequestID - logs latency and request ID to stdout

Codes stored in-memory. No persistence between restarts.

Security notes:

  • Middleware applies globally - every endpoint requires a valid code
  • filepath.Base() sanitization prevents path traversal attacks
  • MaxBytesReader enforces size limits before parsing

License

MIT

About

📡 An tiny HTTP File Server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages