This repository was archived by the owner on Nov 6, 2026. It is now read-only.
Repository navigation
feat: 内置代理订阅节点池(mihomo)+ 双构建 + 健康检查(v4.4.0) - #21
Merged
Merged
Conversation
added 21 commits
October 28, 2026 09:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
免费额度按出口 IP 计量,单机直连很容易被用光。本 PR 增加了「代理订阅节点池」:
配置一个订阅地址,程序在启动阶段拉取订阅、解析成内存节点池并做健康探测,之后按策略
轮换节点;429/403/传输失败自动换下一个出口。
同时引入双构建:
-tags nomihomo,二进制约 8.4 MB,只支持 http/socks5 代理列表;ss/vmess/vless/trojan/hysteria2 等全协议可用。
主要改动
internal/proxypoolgithub.com/metacubex/mihomo/adapter.ParseProxy解析;同时支持纯文本
IP:PORT[:USER:PASS]、URI 行、base64 包裹;sticky(默认,填充:一个节点用到不可用才换) /round_robin(轮询)两种策略;1.1.1.1:443+opencode.ai:443,不消耗额度);internal/zen:新增WithDial(),支持「先经代理隧道、再做 Bun uTLS 握手」;默认直连行为不变。internal/chat:带节点池时按策略取节点;429/403/5xx 或节点不通自动换;无节点池时走原路径。internal/config:新增 4 个PROXY_*环境变量(见下表)。internal/httpapi/health返回统计 + 健康节点列表(?state=healthy|unhealthy|cooling|all);/ip同时返回{direct, proxy}:直连出口和节点池出口各一份;internal/ipinfo改为 ipquery / ip-api /1.1.1.1/cdn-cgi/trace三来源并发竞速,先回先得。mihomo.go(!nomihomo)/mihomo_stub.go(nomihomo);scripts/build-go.sh固定-tags nomihomo;Dockerfile 增加ARG GO_TAGS。新增环境变量
PROXY_SUBSCRIPTION_URLPROXY_MAX_ATTEMPTS5PROXY_STRATEGYstickysticky(填充,用到不可用才换) /round_robin(轮询)PROXY_HEALTH_INTERVAL_SECONDS6000关闭,60–86400Docker 示例:
docker run -d --name oc2api --restart unless-stopped \ -p 8080:8080 \ -e API_KEY=your-key \ -e PROXY_SUBSCRIPTION_URL='https://你的订阅地址' \ ghcr.io/zhuweiyou/oc2api:latest构建体积
go build -tags nomihomo ./cmd/oc2apigo build ./cmd/oc2apiDocker 瘦身镜像:
docker build --build-arg GO_TAGS=nomihomo ...验证
go test ./...与go test -tags nomihomo ./...均通过;go vet ./...通过;unknown=0;[DONE]、工具名正常还原;round_robin下 3 次请求命中 3 个不同节点;/ip能看到direct与proxy两份出口,trace 命中时带warp/loc/colo。/ip返回结构变了:从{ip, source}变为{direct: {...}, proxy: {...}},按旧格式解析
/ip的调用方需要调整。PROXY_SUBSCRIPTION_URL时,对话/SSE/鉴权/整形主链路行为与之前一致;仅
/health在带内核构建下多了proxy字段(纯增量)。/health也不返回节点列表;需要全协议请使用 Docker / 本地版本。
已知限制
dialer-proxy的链式节点会跳过;internal/httpapi、internal/rpc、api/index.js仍没有测试覆盖。Checklist
-tags nomihomo构建均通过节点刷新流程