Skip to content

lgcshy/go-tus-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TUS CLI πŸš€

A simple, clean, and smart TUS (resumable upload) client built with official libraries.

✨ What's New

  • Official TUS Go Client: Uses bdragon300/tusgo for reliable uploads
  • urfave/cli Framework: Clean command structure and better help system
  • Automatic State Management: No more custom state files - the TUS client handles everything
  • 70% Less Code: Simplified, maintainable codebase
  • Better Error Handling: Leverages proven library error handling

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   urfave/cli    │───▢│   TUS CLI v2     │───▢│  tusgo client   β”‚
β”‚   (commands)    β”‚    β”‚   (main.go)      β”‚    β”‚  (state mgmt)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   TUS Server    β”‚
                       β”‚  (resumable)    β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Build

make build

Basic Upload

./tusc -t http://localhost:1080/files upload myfile.txt

With Environment Variables

export TUSC_ENDPOINT=http://localhost:1080/files
export TUSC_CHUNK_SIZE=4
./tusc upload myfile.txt

πŸ“– Usage

Commands

# Upload a file
./tusc upload <file>

# Show server capabilities  
./tusc options

# Default action (upload if file provided)
./tusc <file>

Flags

Flag Short Description Environment Variable
--endpoint -t TUS server endpoint URL TUSC_ENDPOINT
--chunk-size -c Chunk size in MB (default: 2) TUSC_CHUNK_SIZE
--header -H Additional HTTP header TUSC_HEADERS
--retries -r Retry attempts on failure (default: 3, max: 10) TUSC_RETRIES
--verbose Enable verbose output -

Examples

# Basic upload
./tusc -t http://localhost:1080/files upload video.mp4

# Verbose upload with custom headers
./tusc -t http://localhost:1080/files --verbose \
  -H "Authorization:Bearer token123" \
  upload large_file.zip

# Upload with retry attempts for unreliable networks
./tusc -t http://localhost:1080/files -r 5 upload large_file.zip

# Check server capabilities
./tusc -t http://localhost:1080/files options

# Upload with larger chunks and more retries for better performance
./tusc -t http://localhost:1080/files -c 8 -r 5 upload big_file.dat

πŸ”„ Resumable Uploads & Retry Logic

The TUS client automatically handles resumable uploads with intelligent retry logic:

  1. Automatic Resume: If an upload is interrupted, simply run the same command again
  2. State Management: The tusgo library handles all state internally
  3. Smart Retries: Automatic retry with exponential backoff for network errors
  4. No Manual Intervention: No need to track offsets or state files
# Start upload
./tusc -t http://localhost:1080/files upload large_file.zip
# ... upload interrupted ...

# Resume automatically
./tusc -t http://localhost:1080/files upload large_file.zip
# βœ“ Resumes from where it left off

πŸ”„ Retry Behavior

The CLI automatically retries failed uploads using patterns from the official tus-go-client:

  • Retryable Errors: Network timeouts, connection errors, server errors (5xx), checksum mismatches
  • Exponential Backoff: 1s, 2s, 4s, 8s delays between retries
  • Smart Resume: Each retry resumes from the last successful offset
  • Configurable: Set retry count with --retries flag (default: 3, max: 10)
# Upload with 5 retry attempts for unreliable networks
./tusc -t http://localhost:1080/files --retries 5 upload large_file.zip

# Verbose mode shows retry attempts and backoff timing
./tusc -t http://localhost:1080/files --verbose --retries 3 upload file.zip

πŸ› οΈ Development

Setup

make dev-setup

Testing

# Run all tests
make test

# Quick tests only
make test-short

# With coverage
make test-coverage

Quality Checks

# Run all checks
make check

# Individual checks
make fmt    # Format code
make vet    # Vet code  
make lint   # Lint code (requires golangci-lint)

πŸ“Š Version Comparison

Feature v1 (in v1/ folder) Current Version
HTTP Client Custom implementation Official TUS library
State Management Custom file-based Built-in to library
CLI Framework Manual flag parsing urfave/cli
Code Lines ~800 lines ~240 lines
Dependencies None 2 proven libraries
Resumability Manual implementation Automatic
Error Handling Custom retry logic Library-handled
Maintainability Complex Simple

Benefits of Current Version

  • βœ… 70% less code - easier to maintain and understand
  • βœ… More reliable - uses battle-tested libraries
  • βœ… Better UX - cleaner CLI with help system
  • βœ… Automatic resumability - no manual state management
  • βœ… Future-proof - leverages actively maintained libraries

πŸ”§ Configuration

Environment Variables

# Set default endpoint
export TUSC_ENDPOINT=http://your-tus-server.com/files

# Set default chunk size (in MB)
export TUSC_CHUNK_SIZE=4

# Set default retry attempts
export TUSC_RETRIES=5

# Set default headers (comma-separated)
export TUSC_HEADERS="Authorization:Bearer token,X-Custom:value"

Headers Format

# Single header
-H "Authorization:Bearer token123"

# Multiple headers
-H "Authorization:Bearer token" -H "X-Custom:value"

# Via environment
export TUSC_HEADERS="Authorization:Bearer token,X-Custom:value"

🚦 Server Requirements

Your TUS server should support:

  • TUS Protocol 1.0.0
  • Creation Extension - for creating uploads
  • Core Protocol - for uploading data

Optional extensions:

  • Termination - for deleting uploads
  • Expiration - for upload expiration info

πŸ› Troubleshooting

Common Issues

  1. "endpoint is required"

    # Solution: Set endpoint
    ./tusc-v2 -t http://localhost:1080/files upload file.txt
  2. "file not found"

    # Solution: Check file path
    ls -la myfile.txt
    ./tusc-v2 -t http://localhost:1080/files upload ./myfile.txt
  3. "failed to sync with server"

    # Solution: Check server is running and accessible
    curl -I http://localhost:1080/files

Debug Mode

# Enable verbose output for debugging
./tusc --verbose -t http://localhost:1080/files upload file.txt

πŸ“ License

Same as the original project.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ™ Acknowledgments


TUS CLI - Simple, Clean, Smart 🎯

πŸ“ Project Structure

go-tus-cli/
β”œβ”€β”€ main.go           # Current version (simple, clean, smart)
β”œβ”€β”€ main_test.go      # Test suite
β”œβ”€β”€ go.mod           # Dependencies
β”œβ”€β”€ Makefile         # Build targets
β”œβ”€β”€ README.md        # This file
└── v1/              # Legacy version (for reference)
    β”œβ”€β”€ main.go      # Original complex implementation
    β”œβ”€β”€ main_test.go # Original tests
    β”œβ”€β”€ go.mod       # Original dependencies
    └── Makefile     # Original build targets

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published