A minimal command-line tool that performs URL encoding and decoding, similar to the base64 utility. It reads from standard input and writes to standard output.
Installation
go install github.com/Gubarz/urlencode@latest
Usage
URL Encoding
# Encode a string
echo "Hello World!" | urlencode
# Output: Hello+World%21
# Encode a URL
echo "https://example.com/path?query=value&another=value" | urlencode
# Output: https%3A%2F%2Fexample.com%2Fpath%3Fquery%3Dvalue%26another%3Dvalue
# Double Encode a URL
echo "https://example.com/path?query=value&another=value" | urlencode | urlencode
# Output: https%253A%252F%252Fexample.com%252Fpath%253Fquery%253Dvalue%2526another%253Dvalue
# Encode from a file
cat input.txt | urlencode > encoded.txt
URL Decoding
# Decode a string
echo "Hello+World%21" | urlencode -d
# Output: Hello World!
# Decode a URL
echo "https%3A%2F%2Fexample.com%2Fpath%3Fquery%3Dvalue%26another%3Dvalue" | urlencode -d
# Output: https://example.com/path?query=value&another=value
# Double Decode a URL
echo "https%253A%252F%252Fexample.com%252Fpath%253Fquery%253Dvalue%2526another%253Dvalue" | urlencode -d | urlencode -d
# Output: https://example.com/path?query=value&another=value
# Decode from a file
cat encoded.txt | urlencode -d > decoded.txt
Features
- Processes input line-by-line
- Handles special characters and Unicode
- Similar interface to the base64 command
Development
Testing
# Run tests
go test urlencode.go urlencode_test.go
Building
# Build for current platform
go build -o urlencode
# Cross-compile for different platforms
GOOS=windows GOARCH=amd64 go build -o urlencode.exe
GOOS=darwin GOARCH=amd64 go build -o urlencode-mac
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.