feat: migrate to golang

This commit is contained in:
2026-07-19 20:01:38 +08:00
parent 302d4e6bb5
commit a2630df9e0
69 changed files with 4750 additions and 3369 deletions

View File

@ -1,119 +1,138 @@
# Scientific Surfing
A Python package for surfing internet scientifically.
A CLI for surfing the internet scientifically, written in Go.
## Features
- **Clash RSS Subscription Support**: Download and transform clash rss subscription
- **Clash RSS Subscription Support**: Download and transform clash rss subscriptions
- **Hook System**: Customizable scripts for extending functionality
- **Core Configuration Management**: Import, export, and manage core configurations
- **Binary Management**: Automatic updates for core components
- **Binary Management**: Automatic updates for core (mihomo) components
- **Service Management**: Install/start/stop/reload mihomo as a system service on Linux (systemd), macOS (launchd), and Windows (native Service Control Manager)
## Installation
### 1. Clone into local
### 1. Clone and build
```bash
git clone ssh://git@gitea.epss.net.cn:2223/klesh/ss.git
cd ss
python -m venv .venv
./.venv/Scripts/activate
pip install -r requirements.txt
go build -o ss ./cmd/ss
```
### 2. Add the root directory to system PATH
This produces a single `ss` (or `ss.exe` on Windows) binary with no runtime dependencies — templates and hook scripts are embedded in the binary.
### 2. Add the binary to your system PATH
## Quick Start
### Subscription Management
```bash
# add a subscription
python -m ss subscription add <name> <clash-rss-subscription-url>
ss subscription add <name> <clash-rss-subscription-url>
# refresh a subscription (with optional backup)
python -m ss subscription refresh <name> [--backup]
ss subscription refresh <name> [--backup]
# delete a subscription
python -m ss subscription rm <name>
ss subscription rm <name>
# rename a subscription
python -m ss subscription rename <name> <new-name>
ss subscription rename <name> <new-name>
# update subscription URL
python -m ss subscription set-url <name> <new-url>
ss subscription set-url <name> <new-url>
# show the URL for a subscription
ss subscription get-url <name>
# activate a subscription
python -m ss subscription activate <name>
ss subscription activate <name>
# list all subscriptions
python -m ss subscription list
ss subscription list
# show storage information
python -m ss subscription storage
ss subscription storage
```
### Hook Management
```bash
# initialize hooks directory with template scripts
python -m ss hook init
ss hook init
# show hooks directory location and list all scripts
python -m ss hook list
ss hook list
# edit a hook script with system editor
python -m ss hook edit <script-name>
ss hook edit <script-name>
# remove a hook script
python -m ss hook rm <script-name>
ss hook rm <script-name>
```
### Core Configuration Management
```bash
# import configuration from file
python -m ss core config import <file-path> [--config-file <config.yaml>]
ss config import <file-path> [--config-file <config.yaml>]
# export configuration to file
python -m ss core config export <file-path> [--config-file <config.yaml>]
ss config export <file-path> [--config-file <config.yaml>]
# edit configuration with system editor
python -m ss core config edit [--config-file <config.yaml>]
ss config edit [--config-file <config.yaml>]
# reset configuration to default values
python -m ss core config reset [--config-file <config.yaml>]
ss config reset [--config-file <config.yaml>]
# show current configuration
python -m ss core config show [--config-file <config.yaml>]
ss config show [--config-file <config.yaml>]
# apply subscription to generate final config (with advanced options)
python -m ss core config apply \
ss config apply \
[--config-file <config.yaml>] \
[--output-file <output.yaml>] \
[--subscription <subscription-name>]
```
**Options:**
**Options** (available on every `ss config` subcommand):
- `--config-file <config.yaml>`: Use a custom config file instead of the default.
- `--output-file <output.yaml>`: Specify the output path for the generated config file.
- `--subscription <subscription-name>`: Use a specific subscription (not just the active one) for config generation.
### Core Management
```bash
# update scientific-surfing core components
python -m ss core update [--version <version>] [--force]
# update mihomo core binary
ss core update [--version <version>] [--force]
```
### Service Management
```bash
ss service install [--name <name>] [--description <description>]
ss service uninstall [--name <name>]
ss service start [--name <name>]
ss service stop [--name <name>]
ss service restart [--name <name>]
ss service reload [--name <name>] # reload config via mihomo's API, no restart
ss service status [--name <name>]
```
Linux / macOS
```nushell
sudo env SF_CONFIG_DIR=$HOME/basicfiles/cli/ss python3 -m ss core service install
Linux / macOS (installing the service needs root):
```bash
sudo env SF_CONFIG_DIR=$HOME/basicfiles/cli/ss ss service install
```
Windows (run from an elevated/Administrator shell):
```powershell
$env:SF_CONFIG_DIR = "$HOME\basicfiles\cli\ss"
ss.exe service install
```
## Development
This project uses Poetry for dependency management:
```bash
poetry install
poetry run pytest
go build ./...
go vet ./...
go test ./...
```
## License