localgo

module
v0.0.0-...-4f54193 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2025 License: MIT

README ΒΆ

LocalGo

A Go implementation of the LocalSend protocol for secure, cross-platform file sharing.

Go Version Protocol License

πŸš€ Features

Core Functionality
  • βœ… Complete LocalSend v2.1 Protocol - Full compatibility with LocalSend ecosystem
  • βœ… Secure File Transfer - HTTPS with self-signed certificates and PIN protection
  • βœ… Multi-Platform Discovery - Multicast UDP + HTTP fallback for reliable device detection
  • βœ… Cross-Platform - Works on Linux, macOS, and Windows
  • βœ… High Performance - Efficient file transfer with progress tracking

πŸ“¦ Quick Start

Installation

Option 1: One-command installation (Recommended)

# User installation
./scripts/install.sh

# System-wide with service
sudo ./scripts/install.sh --mode system --service --create-user

Option 2: Manual build

git clone https://github.com/bethropolis/localgo.git
cd localgo
make build

Option 3: Go global install

go install github.com/bethropolis/localgo/cmd/localgo-cli@latest
Basic Usage
# Start server to receive files
localgo-cli serve

# Discover devices on network
localgo-cli discover

# Send a file
localgo-cli send --file document.pdf --to "John's Phone"

# Get help
localgo-cli help
localgo-cli help send

πŸ“– Usage Guide

Starting the Server
# Basic server (HTTPS on port 53317)
localgo-cli serve

# Custom configuration
localgo-cli serve --port 8080 --http --alias "MyServer" --pin 123456

# With environment variables
export LOCALSEND_ALIAS="File Server"
export LOCALSEND_DOWNLOAD_DIR="/srv/files"
localgo-cli serve
Sending Files
# Send to specific device
localgo-cli send --file presentation.pptx --to "MacBook Pro"

# Send with custom timeout
localgo-cli send --file large-video.mp4 --to "Desktop" --timeout 300

# Send with custom sender alias
localgo-cli send --file report.pdf --to "Office PC" --alias "Mobile Device"
Discovery and Scanning
# Discover devices (multicast)
localgo-cli discover --timeout 10

# Scan network (HTTP)
localgo-cli scan --port 53317

# JSON output for scripting
localgo-cli discover --json | jq '.devices[].alias'

# Quiet mode for automation
localgo-cli scan --quiet --timeout 5
Device Information
# Show device configuration
localgo-cli info

# JSON format for scripts
localgo-cli info --json

# Check version
localgo-cli version

βš™οΈ Configuration

Environment Variables
# Device Configuration
LOCALSEND_ALIAS="My Device"              # Device name
LOCALSEND_PORT=53317                     # Server port
LOCALSEND_DOWNLOAD_DIR="./downloads"     # Download directory
LOCALSEND_DEVICE_TYPE="desktop"          # Device type

# Network Configuration
LOCALSEND_MULTICAST_GROUP="224.0.0.167" # Multicast address
LOCALSEND_FORCE_HTTP=false               # Use HTTP instead of HTTPS

# Security Configuration
LOCALSEND_PIN="123456"                   # PIN for authentication
LOCALSEND_SECURITY_DIR="./.localgo_security" # Security files location

# Logging Configuration
LOCALSEND_LOG_LEVEL="info"               # Log level (debug,info,warn,error)
LOCALSEND_VERBOSE=false                  # Verbose output
LOCALSEND_NO_COLOR=false                 # Disable colored output
Configuration File

Create localgo.env:

# Copy example configuration
cp scripts/localgo.env.example localgo.env

# Edit configuration
editor localgo.env

# Use configuration
source localgo.env && localgo-cli serve
Command-Line Flags

Each command supports specific flags:

# Serve command
localgo-cli serve --port 8080 --http --pin 123456 --alias "Server" --dir "/tmp" --verbose

# Send command
localgo-cli send --file data.zip --to "Device" --port 8080 --timeout 60 --alias "Sender"

# Discovery commands
localgo-cli discover --timeout 10 --json --quiet
localgo-cli scan --port 8080 --timeout 15 --json

πŸ”§ System Service

Installation
# Install as system service
sudo ./scripts/install.sh --mode system --service --create-user
Service Management
# Enable and start service
sudo systemctl enable localgo
sudo systemctl start localgo

# Check status
sudo systemctl status localgo

# View logs
sudo journalctl -u localgo -f

# Restart service
sudo systemctl restart localgo
Service Configuration

Edit /etc/localgo/localgo.env:

LOCALSEND_ALIAS="File Server"
LOCALSEND_PORT=53317
LOCALSEND_DOWNLOAD_DIR="/srv/localgo/downloads"
LOCALSEND_PIN="secure123"
LOCALSEND_DEVICE_TYPE="server"

πŸ€– Automation & Scripting

JSON Output

Perfect for integration with other tools:

# Get device list
DEVICES=$(localgo-cli scan --json --timeout 5)
echo "$DEVICES" | jq -r '.devices[].alias'

# Check if service is running
localgo-cli info --json | jq -r '.alias + " on port " + (.port|tostring)'

# Monitor file transfers
localgo-cli info --json | jq '.downloadDir'
Batch Operations
# Send multiple files
find /uploads -name "*.pdf" | while read file; do
    localgo-cli send --file "$file" --to "PrintServer"
done

# Health check script
#!/bin/bash
if localgo-cli info --json >/dev/null 2>&1; then
    echo "LocalGo is healthy"
    exit 0
else
    echo "LocalGo is not responding"
    exit 1
fi
Docker Integration
FROM golang:1.19-alpine AS builder
WORKDIR /app
COPY . .
RUN make build

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/localgo-cli .
COPY scripts/localgo.env.example localgo.env
CMD ["./localgo-cli", "serve"]

πŸ’» Development

Building
# Build binary
make build

# Run tests
make test

# Run with coverage
make test-coverage

# Clean build artifacts
make clean
Project Structure
localgo/
β”œβ”€β”€ cmd/localgo-cli/           # CLI application entry point
β”œβ”€β”€ pkg/                       # Core library packages
β”‚   β”œβ”€β”€ cli/                  # CLI output utilities
β”‚   β”œβ”€β”€ config/               # Configuration management
β”‚   β”œβ”€β”€ crypto/               # TLS certificates and fingerprints
β”‚   β”œβ”€β”€ discovery/            # Network discovery (multicast + HTTP)
β”‚   β”œβ”€β”€ httputil/             # HTTP response utilities
β”‚   β”œβ”€β”€ logging/              # Structured logging
β”‚   β”œβ”€β”€ model/                # Data structures (Device, File, DTOs)
β”‚   β”œβ”€β”€ network/              # Network interface utilities
β”‚   β”œβ”€β”€ send/                 # File sending logic
β”‚   β”œβ”€β”€ server/               # HTTP server and handlers
β”‚   └── storage/              # File storage management
β”œβ”€β”€ scripts/                  # Installation and utility scripts
β”œβ”€β”€ protocol/                 # LocalSend protocol specification
└── downloads/                # Default download directory
Contributing
  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: make test
  5. Submit a pull request

🌟 Examples

Home Media Server
# Configure as media server
export LOCALSEND_ALIAS="Home Media Server"
export LOCALSEND_DOWNLOAD_DIR="/media/shared"
export LOCALSEND_DEVICE_TYPE="server"
export LOCALSEND_PIN="family123"

# Install as system service
sudo ./scripts/install.sh --mode system --service --create-user

# Start service
sudo systemctl start localgo
Development Setup
# Configure for development
export LOCALSEND_ALIAS="Dev-$(whoami)"
export LOCALSEND_PORT=8080
export LOCALSEND_FORCE_HTTP=true
export LOCALSEND_VERBOSE=true
export LOCALSEND_LOG_LEVEL="debug"

# Start with verbose logging
localgo-cli serve --verbose
CI/CD Integration
# GitHub Actions example
- name: Test file transfer
  run: |
    # Start receiver
    localgo-cli serve --http --port 8080 &
    sleep 2

    # Send test file
    echo "test data" > test.txt
    localgo-cli send --file test.txt --to "$(localgo-cli info --json | jq -r '.alias')"

    # Verify transfer
    test -f downloads/test.txt
Network Monitoring
#!/bin/bash
# Monitor LocalGo devices on network

while true; do
    echo "=== LocalGo Network Scan $(date) ==="
    localgo-cli scan --json --timeout 10 | jq -r '
        .devices[] |
        "\(.alias) (\(.deviceType)) - \(.ip):\(.port) - \(.protocol)"
    '
    echo
    sleep 60
done

πŸ› οΈ Troubleshooting

Common Issues

Port already in use:

# Check what's using the port
sudo netstat -tlnp | grep 53317

# Use different port
localgo-cli serve --port 8080

Discovery not working:

# Check firewall
sudo ufw status

# Test network connectivity
localgo-cli scan --timeout 10

# Use HTTP discovery
localgo-cli scan --json

Permission denied:

# Fix download directory permissions
sudo chown -R $USER:$USER ~/Downloads/LocalGo

# Check service user permissions (systemd)
sudo journalctl -u localgo -n 50
Debug Mode
# Enable verbose logging
localgo-cli serve --verbose

# Debug network issues
export LOCALSEND_LOG_LEVEL="debug"
localgo-cli discover

πŸ“‹ Protocol Compliance

LocalGo implements the complete LocalSend v2.1 protocol:

  • βœ… Discovery API - /api/localsend/v2/register, /api/localsend/v2/info
  • βœ… Upload API - /api/localsend/v2/prepare-upload, /api/localsend/v2/upload
  • βœ… Download API - /api/localsend/v2/prepare-download, /api/localsend/v2/download
  • βœ… Session Management - Proper session handling with tokens and timeouts
  • βœ… Security - TLS encryption, fingerprint validation, PIN protection
  • βœ… Discovery - Multicast UDP announcements with HTTP fallback

πŸ“œ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments


thank you

Directories ΒΆ

Path Synopsis
cmd
localgo-cli command
pkg
cli
discovery
Package discovery handles device discovery mechanisms
Package discovery handles device discovery mechanisms
httputil
Package httputil provides HTTP utilities for LocalGo
Package httputil provides HTTP utilities for LocalGo
model
Package model contains the data structures used throughout the LocalGo application
Package model contains the data structures used throughout the LocalGo application
network
Package network provides network-related utilities for LocalGo
Package network provides network-related utilities for LocalGo
server
Package server provides HTTP server functionality for LocalGo
Package server provides HTTP server functionality for LocalGo
server/handlers
Package handlers contains HTTP handlers for the LocalGo server
Package handlers contains HTTP handlers for the LocalGo server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL