mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-11-03 20:30:35 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1e8a79c2d2
|
|||
|
be656cca57
|
|||
|
23a85f573b
|
|||
|
fce75baed4
|
|||
| f5686561f9 |
4
.github/workflows/docker.yml
vendored
4
.github/workflows/docker.yml
vendored
@@ -45,7 +45,7 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
build-args: |
|
build-args: |
|
||||||
"version=${{ github.ref_name }}"
|
"version=${{ github.ref_name }}"
|
||||||
@@ -53,3 +53,5 @@ jobs:
|
|||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
file: Containerfile
|
||||||
|
|
||||||
|
|||||||
11
.github/workflows/release.yml
vendored
11
.github/workflows/release.yml
vendored
@@ -13,13 +13,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v5
|
||||||
|
|
||||||
|
- name: Install UPX
|
||||||
|
uses: crazy-max/ghaction-upx@v3
|
||||||
|
with:
|
||||||
|
install-only: true
|
||||||
|
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v5
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
version: 2
|
||||||
project_name: sub2clash
|
project_name: sub2clash
|
||||||
builds:
|
builds:
|
||||||
- env:
|
- env:
|
||||||
@@ -9,19 +10,15 @@ builds:
|
|||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
- arm64
|
- arm64
|
||||||
- arm
|
|
||||||
- "386"
|
- "386"
|
||||||
goarm:
|
|
||||||
- "6"
|
|
||||||
- "7"
|
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X sub2clash/constant.Version={{ .Version }}
|
- -s -w -X github.com/bestnite/sub2clash/constant.Version={{ .Version }}
|
||||||
flags:
|
flags:
|
||||||
- -trimpath
|
- -trimpath
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- formats: ["tar.gz"]
|
||||||
format_overrides:
|
format_overrides:
|
||||||
- format: zip
|
- formats: ["zip"]
|
||||||
goos: windows
|
goos: windows
|
||||||
wrap_in_directory: true
|
wrap_in_directory: true
|
||||||
files:
|
files:
|
||||||
@@ -30,3 +27,19 @@ archives:
|
|||||||
- templates
|
- templates
|
||||||
release:
|
release:
|
||||||
draft: true
|
draft: true
|
||||||
|
upx:
|
||||||
|
- enabled: true
|
||||||
|
compress: best
|
||||||
|
nfpms:
|
||||||
|
- id: sub2clash
|
||||||
|
homepage: https://github.com/bestnite/sub2clash
|
||||||
|
maintainer: Nite <admin@nite07.com>
|
||||||
|
license: "MIT"
|
||||||
|
formats:
|
||||||
|
- apk
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
- termux.deb
|
||||||
|
- archlinux
|
||||||
|
provides:
|
||||||
|
- sub2clash
|
||||||
|
|||||||
74
API.md
74
API.md
@@ -1,74 +0,0 @@
|
|||||||
# `GET /convert/:config`
|
|
||||||
|
|
||||||
获取 Clash/Clash.Meta 配置链接
|
|
||||||
|
|
||||||
| Path 参数 | 类型 | 说明 |
|
|
||||||
| --------- | ------ | ---------------------------------------------- |
|
|
||||||
| config | string | Base64 URL Safe 编码后的 JSON 字符串,格式如下 |
|
|
||||||
|
|
||||||
## `config` JSON 结构
|
|
||||||
|
|
||||||
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
|
||||||
| ------------------ | ----------------- | ------------------------ | --------- | --------------------------------------------------------------------------------- |
|
|
||||||
| clashType | int | 是 | 1 | 配置文件类型 (1: Clash, 2: Clash.Meta) |
|
|
||||||
| subscriptions | []string | sub/proxy 至少有一项存在 | - | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个) |
|
|
||||||
| proxies | []string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个) |
|
|
||||||
| refresh | bool | 否 | `false` | 强制刷新配置(默认缓存 5 分钟) |
|
|
||||||
| template | string | 否 | - | 外部模板链接或内部模板名称 |
|
|
||||||
| ruleProviders | []RuleProvider | 否 | - | 规则 |
|
|
||||||
| rules | []Rule | 否 | - | 规则 |
|
|
||||||
| autoTest | bool | 否 | `false` | 国家策略组是否自动测速 |
|
|
||||||
| lazy | bool | 否 | `false` | 自动测速是否启用 lazy |
|
|
||||||
| sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` |
|
|
||||||
| replace | map[string]string | 否 | - | 通过正则表达式重命名节点 |
|
|
||||||
| remove | string | 否 | - | 通过正则表达式删除节点 |
|
|
||||||
| nodeList | bool | 否 | `false` | 只输出节点 |
|
|
||||||
| ignoreCountryGroup | bool | 否 | `false` | 是否忽略国家分组 |
|
|
||||||
| userAgent | string | 否 | - | 订阅 user-agent |
|
|
||||||
| useUDP | bool | 否 | `false` | 是否使用 UDP |
|
|
||||||
|
|
||||||
### `RuleProvider` 结构
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
| -------- | ------ | ---------------------------------------------------------------- |
|
|
||||||
| behavior | string | rule-set 的 behavior |
|
|
||||||
| url | string | rule-set 的 url |
|
|
||||||
| group | string | 该规则集使用的策略组名 |
|
|
||||||
| prepend | bool | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
|
|
||||||
| name | string | 该 rule-provider 的名称,不能重复 |
|
|
||||||
|
|
||||||
### `Rule` 结构
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
| ------- | ------ | ---------------------------------------------------------------- |
|
|
||||||
| rule | string | 规则 |
|
|
||||||
| prepend | bool | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
|
|
||||||
|
|
||||||
# `POST /short`
|
|
||||||
|
|
||||||
获取短链,Content-Type 为 `application/json`
|
|
||||||
具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
|
|
||||||
|
|
||||||
| Body 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
|
||||||
| --------- | ------ | -------- | ------ | ------------------------- |
|
|
||||||
| url | string | 是 | - | 需要转换的 Query 参数部分 |
|
|
||||||
| password | string | 否 | - | 短链密码 |
|
|
||||||
|
|
||||||
# `GET /s/:hash`
|
|
||||||
|
|
||||||
短链跳转
|
|
||||||
`hash` 为动态路由参数,可以通过 `/short` 接口获取
|
|
||||||
|
|
||||||
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
|
||||||
| ---------- | ------ | -------- | ------ | -------- |
|
|
||||||
| password | string | 否 | - | 短链密码 |
|
|
||||||
|
|
||||||
# `PUT /short`
|
|
||||||
|
|
||||||
更新短链,Content-Type 为 `application/json`
|
|
||||||
|
|
||||||
| Body 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
|
||||||
| --------- | ------ | -------- | ------ | ------------------------- |
|
|
||||||
| url | string | 是 | - | 需要转换的 Query 参数部分 |
|
|
||||||
| password | string | 否 | - | 短链密码 |
|
|
||||||
| hash | string | 是 | - | 短链 hash |
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.21-alpine as builder
|
FROM golang:1.25 as builder
|
||||||
LABEL authors="nite07"
|
LABEL authors="nite07"
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
75
README.md
75
README.md
@@ -59,7 +59,80 @@
|
|||||||
|
|
||||||
### API
|
### API
|
||||||
|
|
||||||
[API 文档](./API.md)
|
#### `GET /convert/:config`
|
||||||
|
|
||||||
|
获取 Clash/Clash.Meta 配置链接
|
||||||
|
|
||||||
|
| Path 参数 | 类型 | 说明 |
|
||||||
|
| --------- | ------ | ---------------------------------------------- |
|
||||||
|
| config | string | Base64 URL Safe 编码后的 JSON 字符串,格式如下 |
|
||||||
|
|
||||||
|
##### `config` JSON 结构
|
||||||
|
|
||||||
|
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
||||||
|
| ------------------ | ----------------- | ------------------------ | --------- | -------------------------------------------------------------------------------------------------------- |
|
||||||
|
| clashType | int | 是 | 1 | 配置文件类型 (1: Clash, 2: Clash.Meta) |
|
||||||
|
| subscriptions | []string | sub/proxy 至少有一项存在 | - | 订阅链接(v2ray 或 clash 格式),可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个) |
|
||||||
|
| proxies | []string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个) |
|
||||||
|
| refresh | bool | 否 | `false` | 强制刷新配置(默认缓存 5 分钟) |
|
||||||
|
| template | string | 否 | - | 外部模板链接或内部模板名称 |
|
||||||
|
| ruleProviders | []RuleProvider | 否 | - | 规则 |
|
||||||
|
| rules | []Rule | 否 | - | 规则 |
|
||||||
|
| autoTest | bool | 否 | `false` | 国家策略组是否自动测速 |
|
||||||
|
| lazy | bool | 否 | `false` | 自动测速是否启用 lazy |
|
||||||
|
| sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` |
|
||||||
|
| replace | map[string]string | 否 | - | 通过正则表达式重命名节点 |
|
||||||
|
| remove | string | 否 | - | 通过正则表达式删除节点 |
|
||||||
|
| nodeList | bool | 否 | `false` | 只输出节点 |
|
||||||
|
| ignoreCountryGroup | bool | 否 | `false` | 是否忽略国家分组 |
|
||||||
|
| userAgent | string | 否 | - | 订阅 user-agent |
|
||||||
|
| useUDP | bool | 否 | `false` | 是否使用 UDP |
|
||||||
|
|
||||||
|
###### `RuleProvider` 结构
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| -------- | ------ | ---------------------------------------------------------------- |
|
||||||
|
| behavior | string | rule-set 的 behavior |
|
||||||
|
| url | string | rule-set 的 url |
|
||||||
|
| group | string | 该规则集使用的策略组名 |
|
||||||
|
| prepend | bool | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
|
||||||
|
| name | string | 该 rule-provider 的名称,不能重复 |
|
||||||
|
|
||||||
|
###### `Rule` 结构
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ------- | ------ | ---------------------------------------------------------------- |
|
||||||
|
| rule | string | 规则 |
|
||||||
|
| prepend | bool | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
|
||||||
|
|
||||||
|
#### `POST /short`
|
||||||
|
|
||||||
|
获取短链,Content-Type 为 `application/json`
|
||||||
|
具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
|
||||||
|
|
||||||
|
| Body 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
||||||
|
| --------- | ------ | -------- | ------ | ------------------------- |
|
||||||
|
| url | string | 是 | - | 需要转换的 Query 参数部分 |
|
||||||
|
| password | string | 否 | - | 短链密码 |
|
||||||
|
|
||||||
|
#### `GET /s/:hash`
|
||||||
|
|
||||||
|
短链跳转
|
||||||
|
`hash` 为动态路由参数,可以通过 `/short` 接口获取
|
||||||
|
|
||||||
|
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
||||||
|
| ---------- | ------ | -------- | ------ | -------- |
|
||||||
|
| password | string | 否 | - | 短链密码 |
|
||||||
|
|
||||||
|
#### `PUT /short`
|
||||||
|
|
||||||
|
更新短链,Content-Type 为 `application/json`
|
||||||
|
|
||||||
|
| Body 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|
||||||
|
| --------- | ------ | -------- | ------ | ------------------------- |
|
||||||
|
| url | string | 是 | - | 需要转换的 Query 参数部分 |
|
||||||
|
| password | string | 否 | - | 短链密码 |
|
||||||
|
| hash | string | 是 | - | 短链 hash |
|
||||||
|
|
||||||
### 模板
|
### 模板
|
||||||
|
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ func NewTemplateLoadError(template string, cause error) *CommonError {
|
|||||||
return NewError(ErrTemplateLoad, fmt.Sprintf("failed to load template: %s", template), cause)
|
return NewError(ErrTemplateLoad, fmt.Sprintf("failed to load template: %s", template), cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTemplateParseError(cause error) *CommonError {
|
func NewTemplateParseError(data []byte, cause error) *CommonError {
|
||||||
return NewError(ErrTemplateParse, "failed to parse template", cause)
|
return NewError(ErrTemplateParse, fmt.Sprintf("failed to parse template: %s", data), cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscription errors
|
// Subscription errors
|
||||||
@@ -142,8 +142,8 @@ func NewSubscriptionLoadError(url string, cause error) *CommonError {
|
|||||||
return NewError(ErrSubscriptionLoad, fmt.Sprintf("failed to load subscription: %s", url), cause)
|
return NewError(ErrSubscriptionLoad, fmt.Sprintf("failed to load subscription: %s", url), cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSubscriptionParseError(cause error) *CommonError {
|
func NewSubscriptionParseError(data []byte, cause error) *CommonError {
|
||||||
return NewError(ErrSubscriptionParse, "failed to parse subscription", cause)
|
return NewError(ErrSubscriptionParse, fmt.Sprintf("failed to parse subscription: %s", string(data)), cause)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regex errors
|
// Regex errors
|
||||||
|
|||||||
@@ -129,22 +129,22 @@ func BuildSub(clashType model.ClashType, query model.ConvertConfig, template str
|
|||||||
err = yaml.Unmarshal(templateBytes, &temp)
|
err = yaml.Unmarshal(templateBytes, &temp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Debug("parse template failed", zap.Error(err))
|
logger.Logger.Debug("parse template failed", zap.Error(err))
|
||||||
return nil, NewTemplateParseError(err)
|
return nil, NewTemplateParseError(templateBytes, err)
|
||||||
}
|
}
|
||||||
var proxyList []P.Proxy
|
var proxyList []P.Proxy
|
||||||
|
|
||||||
for i := range query.Subs {
|
for i := range query.Subs {
|
||||||
data, err := LoadSubscription(query.Subs[i], query.Refresh, query.UserAgent, cacheExpire, retryTimes)
|
data, err := LoadSubscription(query.Subs[i], query.Refresh, query.UserAgent, cacheExpire, retryTimes)
|
||||||
subName := ""
|
|
||||||
if strings.Contains(query.Subs[i], "#") {
|
|
||||||
subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Debug(
|
logger.Logger.Debug(
|
||||||
"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
|
"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
|
||||||
)
|
)
|
||||||
return nil, NewSubscriptionLoadError(query.Subs[i], err)
|
return nil, NewSubscriptionLoadError(query.Subs[i], err)
|
||||||
}
|
}
|
||||||
|
subName := ""
|
||||||
|
if strings.Contains(query.Subs[i], "#") {
|
||||||
|
subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
|
||||||
|
}
|
||||||
|
|
||||||
err = yaml.Unmarshal(data, &sub)
|
err = yaml.Unmarshal(data, &sub)
|
||||||
var newProxies []P.Proxy
|
var newProxies []P.Proxy
|
||||||
@@ -161,14 +161,14 @@ func BuildSub(clashType model.ClashType, query model.ConvertConfig, template str
|
|||||||
}
|
}
|
||||||
newProxies = p
|
newProxies = p
|
||||||
} else {
|
} else {
|
||||||
base64, err := utils.DecodeBase64(string(data), true)
|
base64, err := utils.DecodeBase64(string(data), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger.Debug(
|
logger.Logger.Debug(
|
||||||
"parse subscription failed", zap.String("url", query.Subs[i]),
|
"parse subscription failed", zap.String("url", query.Subs[i]),
|
||||||
zap.String("data", string(data)),
|
zap.String("data", string(data)),
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
return nil, NewSubscriptionParseError(err)
|
return nil, NewSubscriptionParseError(data, err)
|
||||||
}
|
}
|
||||||
p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(base64, "\n")...)
|
p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(base64, "\n")...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -3,11 +3,27 @@ package common
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadTemplate(templatePath string) ([]byte, error) {
|
const templatesDir = "templates"
|
||||||
if _, err := os.Stat(templatePath); err == nil {
|
|
||||||
file, err := os.Open(templatePath)
|
// LoadTemplate 只读取运行目录下的 templates 目录,防止其他文件内容泄漏
|
||||||
|
func LoadTemplate(templateName string) ([]byte, error) {
|
||||||
|
// 清理路径,防止目录遍历攻击
|
||||||
|
cleanTemplateName := filepath.Clean(templateName)
|
||||||
|
|
||||||
|
// 检查是否尝试访问父目录
|
||||||
|
if strings.HasPrefix(cleanTemplateName, "..") || strings.Contains(cleanTemplateName, string(filepath.Separator)+".."+string(filepath.Separator)) {
|
||||||
|
return nil, NewFileNotFoundError(templateName) // 拒绝包含父目录的路径
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建完整路径,确保只从 templates 目录读取
|
||||||
|
fullPath := filepath.Join(templatesDir, cleanTemplateName)
|
||||||
|
|
||||||
|
if _, err := os.Stat(fullPath); err == nil {
|
||||||
|
file, err := os.Open(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -22,5 +38,5 @@ func LoadTemplate(templatePath string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
return nil, NewFileNotFoundError(templatePath)
|
return nil, NewFileNotFoundError(templateName)
|
||||||
}
|
}
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,8 +1,6 @@
|
|||||||
module github.com/bestnite/sub2clash
|
module github.com/bestnite/sub2clash
|
||||||
|
|
||||||
go 1.21.0
|
go 1.25
|
||||||
|
|
||||||
toolchain go1.24.3
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.10.1
|
github.com/gin-gonic/gin v1.10.1
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ package proxy
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/anytls.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/anytls.go
|
||||||
type Anytls struct {
|
type Anytls struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
ALPN []string `yaml:"alpn,omitempty"`
|
ALPN []string `yaml:"alpn,omitempty"`
|
||||||
SNI string `yaml:"sni,omitempty"`
|
SNI string `yaml:"sni,omitempty"`
|
||||||
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
||||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||||
UDP bool `yaml:"udp,omitempty"`
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
||||||
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
||||||
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,28 +2,28 @@ package proxy
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria.go
|
||||||
type Hysteria struct {
|
type Hysteria struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port,omitempty"`
|
Port IntOrString `yaml:"port,omitempty"`
|
||||||
Ports string `yaml:"ports,omitempty"`
|
Ports string `yaml:"ports,omitempty"`
|
||||||
Protocol string `yaml:"protocol,omitempty"`
|
Protocol string `yaml:"protocol,omitempty"`
|
||||||
ObfsProtocol string `yaml:"obfs-protocol,omitempty"` // compatible with Stash
|
ObfsProtocol string `yaml:"obfs-protocol,omitempty"` // compatible with Stash
|
||||||
Up string `yaml:"up"`
|
Up string `yaml:"up"`
|
||||||
UpSpeed int `yaml:"up-speed,omitempty"` // compatible with Stash
|
UpSpeed int `yaml:"up-speed,omitempty"` // compatible with Stash
|
||||||
Down string `yaml:"down"`
|
Down string `yaml:"down"`
|
||||||
DownSpeed int `yaml:"down-speed,omitempty"` // compatible with Stash
|
DownSpeed int `yaml:"down-speed,omitempty"` // compatible with Stash
|
||||||
Auth string `yaml:"auth,omitempty"`
|
Auth string `yaml:"auth,omitempty"`
|
||||||
AuthString string `yaml:"auth-str,omitempty"`
|
AuthString string `yaml:"auth-str,omitempty"`
|
||||||
Obfs string `yaml:"obfs,omitempty"`
|
Obfs string `yaml:"obfs,omitempty"`
|
||||||
SNI string `yaml:"sni,omitempty"`
|
SNI string `yaml:"sni,omitempty"`
|
||||||
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
||||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||||
ALPN []string `yaml:"alpn,omitempty"`
|
ALPN []string `yaml:"alpn,omitempty"`
|
||||||
CustomCA string `yaml:"ca,omitempty"`
|
CustomCA string `yaml:"ca,omitempty"`
|
||||||
CustomCAString string `yaml:"ca-str,omitempty"`
|
CustomCAString string `yaml:"ca-str,omitempty"`
|
||||||
ReceiveWindowConn int `yaml:"recv-window-conn,omitempty"`
|
ReceiveWindowConn int `yaml:"recv-window-conn,omitempty"`
|
||||||
ReceiveWindow int `yaml:"recv-window,omitempty"`
|
ReceiveWindow int `yaml:"recv-window,omitempty"`
|
||||||
DisableMTUDiscovery bool `yaml:"disable-mtu-discovery,omitempty"`
|
DisableMTUDiscovery bool `yaml:"disable-mtu-discovery,omitempty"`
|
||||||
FastOpen bool `yaml:"fast-open,omitempty"`
|
FastOpen bool `yaml:"fast-open,omitempty"`
|
||||||
HopInterval int `yaml:"hop-interval,omitempty"`
|
HopInterval int `yaml:"hop-interval,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,24 @@ package proxy
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria2.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria2.go
|
||||||
type Hysteria2 struct {
|
type Hysteria2 struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port,omitempty"`
|
Port IntOrString `yaml:"port,omitempty"`
|
||||||
Ports string `yaml:"ports,omitempty"`
|
Ports string `yaml:"ports,omitempty"`
|
||||||
HopInterval int `yaml:"hop-interval,omitempty"`
|
HopInterval int `yaml:"hop-interval,omitempty"`
|
||||||
Up string `yaml:"up,omitempty"`
|
Up string `yaml:"up,omitempty"`
|
||||||
Down string `yaml:"down,omitempty"`
|
Down string `yaml:"down,omitempty"`
|
||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
Obfs string `yaml:"obfs,omitempty"`
|
Obfs string `yaml:"obfs,omitempty"`
|
||||||
ObfsPassword string `yaml:"obfs-password,omitempty"`
|
ObfsPassword string `yaml:"obfs-password,omitempty"`
|
||||||
SNI string `yaml:"sni,omitempty"`
|
SNI string `yaml:"sni,omitempty"`
|
||||||
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
ECHOpts ECHOptions `yaml:"ech-opts,omitempty"`
|
||||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||||
ALPN []string `yaml:"alpn,omitempty"`
|
ALPN []string `yaml:"alpn,omitempty"`
|
||||||
CustomCA string `yaml:"ca,omitempty"`
|
CustomCA string `yaml:"ca,omitempty"`
|
||||||
CustomCAString string `yaml:"ca-str,omitempty"`
|
CustomCAString string `yaml:"ca-str,omitempty"`
|
||||||
CWND int `yaml:"cwnd,omitempty"`
|
CWND int `yaml:"cwnd,omitempty"`
|
||||||
UdpMTU int `yaml:"udp-mtu,omitempty"`
|
UdpMTU int `yaml:"udp-mtu,omitempty"`
|
||||||
|
|
||||||
// quic-go special config
|
// quic-go special config
|
||||||
InitialStreamReceiveWindow uint64 `yaml:"initial-stream-receive-window,omitempty"`
|
InitialStreamReceiveWindow uint64 `yaml:"initial-stream-receive-window,omitempty"`
|
||||||
|
|||||||
@@ -2,10 +2,31 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IntOrString int
|
||||||
|
|
||||||
|
func (i *IntOrString) UnmarshalYAML(value *yaml.Node) error {
|
||||||
|
intVal := 0
|
||||||
|
err := yaml.Unmarshal([]byte(value.Value), &intVal)
|
||||||
|
if err == nil {
|
||||||
|
*i = IntOrString(intVal)
|
||||||
|
}
|
||||||
|
strVal := ""
|
||||||
|
err = yaml.Unmarshal([]byte(value.Value), &strVal)
|
||||||
|
if err == nil {
|
||||||
|
_int, err := strconv.ParseInt(strVal, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
*i = IntOrString(_int)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type HTTPOptions struct {
|
type HTTPOptions struct {
|
||||||
Method string `yaml:"method,omitempty"`
|
Method string `yaml:"method,omitempty"`
|
||||||
Path []string `yaml:"path,omitempty"`
|
Path []string `yaml:"path,omitempty"`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package proxy
|
|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocks.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocks.go
|
||||||
type ShadowSocks struct {
|
type ShadowSocks struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
Cipher string `yaml:"cipher"`
|
Cipher string `yaml:"cipher"`
|
||||||
UDP bool `yaml:"udp,omitempty"`
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package proxy
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocksr.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocksr.go
|
||||||
type ShadowSocksR struct {
|
type ShadowSocksR struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
Cipher string `yaml:"cipher"`
|
Cipher string `yaml:"cipher"`
|
||||||
Obfs string `yaml:"obfs"`
|
Obfs string `yaml:"obfs"`
|
||||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||||
Protocol string `yaml:"protocol"`
|
Protocol string `yaml:"protocol"`
|
||||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||||
UDP bool `yaml:"udp,omitempty"`
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package proxy
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/socks5.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/socks5.go
|
||||||
type Socks struct {
|
type Socks struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
UserName string `yaml:"username,omitempty"`
|
UserName string `yaml:"username,omitempty"`
|
||||||
Password string `yaml:"password,omitempty"`
|
Password string `yaml:"password,omitempty"`
|
||||||
TLS bool `yaml:"tls,omitempty"`
|
TLS bool `yaml:"tls,omitempty"`
|
||||||
UDP bool `yaml:"udp,omitempty"`
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package proxy
|
|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/trojan.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/trojan.go
|
||||||
type Trojan struct {
|
type Trojan struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
ALPN []string `yaml:"alpn,omitempty"`
|
ALPN []string `yaml:"alpn,omitempty"`
|
||||||
SNI string `yaml:"sni,omitempty"`
|
SNI string `yaml:"sni,omitempty"`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package proxy
|
|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vless.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vless.go
|
||||||
type Vless struct {
|
type Vless struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
UUID string `yaml:"uuid"`
|
UUID string `yaml:"uuid"`
|
||||||
Flow string `yaml:"flow,omitempty"`
|
Flow string `yaml:"flow,omitempty"`
|
||||||
TLS bool `yaml:"tls,omitempty"`
|
TLS bool `yaml:"tls,omitempty"`
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package proxy
|
|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vmess.go
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vmess.go
|
||||||
type Vmess struct {
|
type Vmess struct {
|
||||||
Server string `yaml:"server"`
|
Server string `yaml:"server"`
|
||||||
Port int `yaml:"port"`
|
Port IntOrString `yaml:"port"`
|
||||||
UUID string `yaml:"uuid"`
|
UUID string `yaml:"uuid"`
|
||||||
AlterID int `yaml:"alterId"`
|
AlterID IntOrString `yaml:"alterId"`
|
||||||
Cipher string `yaml:"cipher"`
|
Cipher string `yaml:"cipher"`
|
||||||
UDP bool `yaml:"udp,omitempty"`
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
Network string `yaml:"network,omitempty"`
|
Network string `yaml:"network,omitempty"`
|
||||||
|
|||||||
@@ -14,51 +14,51 @@ type NodeList struct {
|
|||||||
|
|
||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/config/config.go RawConfig
|
// https://github.com/MetaCubeX/mihomo/blob/Meta/config/config.go RawConfig
|
||||||
type Subscription struct {
|
type Subscription struct {
|
||||||
Port int `yaml:"port,omitempty" json:"port"`
|
Port proxy.IntOrString `yaml:"port,omitempty" json:"port"`
|
||||||
SocksPort int `yaml:"socks-port,omitempty" json:"socks-port"`
|
SocksPort proxy.IntOrString `yaml:"socks-port,omitempty" json:"socks-port"`
|
||||||
RedirPort int `yaml:"redir-port,omitempty" json:"redir-port"`
|
RedirPort proxy.IntOrString `yaml:"redir-port,omitempty" json:"redir-port"`
|
||||||
TProxyPort int `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
|
TProxyPort proxy.IntOrString `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
|
||||||
MixedPort int `yaml:"mixed-port,omitempty" json:"mixed-port"`
|
MixedPort proxy.IntOrString `yaml:"mixed-port,omitempty" json:"mixed-port"`
|
||||||
ShadowSocksConfig string `yaml:"ss-config,omitempty" json:"ss-config"`
|
ShadowSocksConfig string `yaml:"ss-config,omitempty" json:"ss-config"`
|
||||||
VmessConfig string `yaml:"vmess-config,omitempty" json:"vmess-config"`
|
VmessConfig string `yaml:"vmess-config,omitempty" json:"vmess-config"`
|
||||||
InboundTfo bool `yaml:"inbound-tfo,omitempty" json:"inbound-tfo"`
|
InboundTfo bool `yaml:"inbound-tfo,omitempty" json:"inbound-tfo"`
|
||||||
InboundMPTCP bool `yaml:"inbound-mptcp,omitempty" json:"inbound-mptcp"`
|
InboundMPTCP bool `yaml:"inbound-mptcp,omitempty" json:"inbound-mptcp"`
|
||||||
Authentication []string `yaml:"authentication,omitempty" json:"authentication"`
|
Authentication []string `yaml:"authentication,omitempty" json:"authentication"`
|
||||||
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes,omitempty" json:"skip-auth-prefixes"`
|
SkipAuthPrefixes []netip.Prefix `yaml:"skip-auth-prefixes,omitempty" json:"skip-auth-prefixes"`
|
||||||
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips,omitempty" json:"lan-allowed-ips"`
|
LanAllowedIPs []netip.Prefix `yaml:"lan-allowed-ips,omitempty" json:"lan-allowed-ips"`
|
||||||
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips,omitempty" json:"lan-disallowed-ips"`
|
LanDisAllowedIPs []netip.Prefix `yaml:"lan-disallowed-ips,omitempty" json:"lan-disallowed-ips"`
|
||||||
AllowLan bool `yaml:"allow-lan,omitempty" json:"allow-lan"`
|
AllowLan bool `yaml:"allow-lan,omitempty" json:"allow-lan"`
|
||||||
BindAddress string `yaml:"bind-address,omitempty" json:"bind-address"`
|
BindAddress string `yaml:"bind-address,omitempty" json:"bind-address"`
|
||||||
Mode string `yaml:"mode,omitempty" json:"mode"`
|
Mode string `yaml:"mode,omitempty" json:"mode"`
|
||||||
UnifiedDelay bool `yaml:"unified-delay,omitempty" json:"unified-delay"`
|
UnifiedDelay bool `yaml:"unified-delay,omitempty" json:"unified-delay"`
|
||||||
LogLevel string `yaml:"log-level,omitempty" json:"log-level"`
|
LogLevel string `yaml:"log-level,omitempty" json:"log-level"`
|
||||||
IPv6 bool `yaml:"ipv6,omitempty" json:"ipv6"`
|
IPv6 bool `yaml:"ipv6,omitempty" json:"ipv6"`
|
||||||
ExternalController string `yaml:"external-controller,omitempty" json:"external-controller"`
|
ExternalController string `yaml:"external-controller,omitempty" json:"external-controller"`
|
||||||
ExternalControllerPipe string `yaml:"external-controller-pipe,omitempty" json:"external-controller-pipe"`
|
ExternalControllerPipe string `yaml:"external-controller-pipe,omitempty" json:"external-controller-pipe"`
|
||||||
ExternalControllerUnix string `yaml:"external-controller-unix,omitempty" json:"external-controller-unix"`
|
ExternalControllerUnix string `yaml:"external-controller-unix,omitempty" json:"external-controller-unix"`
|
||||||
ExternalControllerTLS string `yaml:"external-controller-tls,omitempty" json:"external-controller-tls"`
|
ExternalControllerTLS string `yaml:"external-controller-tls,omitempty" json:"external-controller-tls"`
|
||||||
ExternalControllerCors C.RawCors `yaml:"external-controller-cors,omitempty" json:"external-controller-cors"`
|
ExternalControllerCors C.RawCors `yaml:"external-controller-cors,omitempty" json:"external-controller-cors"`
|
||||||
ExternalUI string `yaml:"external-ui,omitempty" json:"external-ui"`
|
ExternalUI string `yaml:"external-ui,omitempty" json:"external-ui"`
|
||||||
ExternalUIURL string `yaml:"external-ui-url,omitempty" json:"external-ui-url"`
|
ExternalUIURL string `yaml:"external-ui-url,omitempty" json:"external-ui-url"`
|
||||||
ExternalUIName string `yaml:"external-ui-name,omitempty" json:"external-ui-name"`
|
ExternalUIName string `yaml:"external-ui-name,omitempty" json:"external-ui-name"`
|
||||||
ExternalDohServer string `yaml:"external-doh-server,omitempty" json:"external-doh-server"`
|
ExternalDohServer string `yaml:"external-doh-server,omitempty" json:"external-doh-server"`
|
||||||
Secret string `yaml:"secret,omitempty" json:"secret"`
|
Secret string `yaml:"secret,omitempty" json:"secret"`
|
||||||
Interface string `yaml:"interface-name,omitempty" json:"interface-name"`
|
Interface string `yaml:"interface-name,omitempty" json:"interface-name"`
|
||||||
RoutingMark int `yaml:"routing-mark,omitempty" json:"routing-mark"`
|
RoutingMark int `yaml:"routing-mark,omitempty" json:"routing-mark"`
|
||||||
Tunnels []LC.Tunnel `yaml:"tunnels,omitempty" json:"tunnels"`
|
Tunnels []LC.Tunnel `yaml:"tunnels,omitempty" json:"tunnels"`
|
||||||
GeoAutoUpdate bool `yaml:"geo-auto-update,omitempty" json:"geo-auto-update"`
|
GeoAutoUpdate bool `yaml:"geo-auto-update,omitempty" json:"geo-auto-update"`
|
||||||
GeoUpdateInterval int `yaml:"geo-update-interval,omitempty" json:"geo-update-interval"`
|
GeoUpdateInterval int `yaml:"geo-update-interval,omitempty" json:"geo-update-interval"`
|
||||||
GeodataMode bool `yaml:"geodata-mode,omitempty" json:"geodata-mode"`
|
GeodataMode bool `yaml:"geodata-mode,omitempty" json:"geodata-mode"`
|
||||||
GeodataLoader string `yaml:"geodata-loader,omitempty" json:"geodata-loader"`
|
GeodataLoader string `yaml:"geodata-loader,omitempty" json:"geodata-loader"`
|
||||||
GeositeMatcher string `yaml:"geosite-matcher,omitempty" json:"geosite-matcher"`
|
GeositeMatcher string `yaml:"geosite-matcher,omitempty" json:"geosite-matcher"`
|
||||||
TCPConcurrent bool `yaml:"tcp-concurrent,omitempty" json:"tcp-concurrent"`
|
TCPConcurrent bool `yaml:"tcp-concurrent,omitempty" json:"tcp-concurrent"`
|
||||||
FindProcessMode string `yaml:"find-process-mode,omitempty" json:"find-process-mode"`
|
FindProcessMode string `yaml:"find-process-mode,omitempty" json:"find-process-mode"`
|
||||||
GlobalClientFingerprint string `yaml:"global-client-fingerprint,omitempty" json:"global-client-fingerprint"`
|
GlobalClientFingerprint string `yaml:"global-client-fingerprint,omitempty" json:"global-client-fingerprint"`
|
||||||
GlobalUA string `yaml:"global-ua,omitempty" json:"global-ua"`
|
GlobalUA string `yaml:"global-ua,omitempty" json:"global-ua"`
|
||||||
ETagSupport bool `yaml:"etag-support,omitempty" json:"etag-support"`
|
ETagSupport bool `yaml:"etag-support,omitempty" json:"etag-support"`
|
||||||
KeepAliveIdle int `yaml:"keep-alive-idle,omitempty" json:"keep-alive-idle"`
|
KeepAliveIdle int `yaml:"keep-alive-idle,omitempty" json:"keep-alive-idle"`
|
||||||
KeepAliveInterval int `yaml:"keep-alive-interval,omitempty" json:"keep-alive-interval"`
|
KeepAliveInterval int `yaml:"keep-alive-interval,omitempty" json:"keep-alive-interval"`
|
||||||
DisableKeepAlive bool `yaml:"disable-keep-alive,omitempty" json:"disable-keep-alive"`
|
DisableKeepAlive bool `yaml:"disable-keep-alive,omitempty" json:"disable-keep-alive"`
|
||||||
|
|
||||||
ProxyProvider map[string]map[string]any `yaml:"proxy-providers,omitempty" json:"proxy-providers"`
|
ProxyProvider map[string]map[string]any `yaml:"proxy-providers,omitempty" json:"proxy-providers"`
|
||||||
RuleProvider map[string]RuleProvider `yaml:"rule-providers,omitempty" json:"rule-providers"`
|
RuleProvider map[string]RuleProvider `yaml:"rule-providers,omitempty" json:"rule-providers"`
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (p *AnytlsParser) Parse(config ParseConfig, proxy string) (P.Proxy, error)
|
|||||||
Name: remarks,
|
Name: remarks,
|
||||||
Anytls: P.Anytls{
|
Anytls: P.Anytls{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
Password: password,
|
Password: password,
|
||||||
SNI: sni,
|
SNI: sni,
|
||||||
SkipCertVerify: insecureBool,
|
SkipCertVerify: insecureBool,
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (p *HysteriaParser) Parse(config ParseConfig, proxy string) (P.Proxy, error
|
|||||||
Name: remarks,
|
Name: remarks,
|
||||||
Hysteria: P.Hysteria{
|
Hysteria: P.Hysteria{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
Up: upmbps,
|
Up: upmbps,
|
||||||
Down: downmbps,
|
Down: downmbps,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func (p *Hysteria2Parser) Parse(config ParseConfig, proxy string) (P.Proxy, erro
|
|||||||
Name: remarks,
|
Name: remarks,
|
||||||
Hysteria2: P.Hysteria2{
|
Hysteria2: P.Hysteria2{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
Password: password,
|
Password: password,
|
||||||
Obfs: obfs,
|
Obfs: obfs,
|
||||||
ObfsPassword: obfsPassword,
|
ObfsPassword: obfsPassword,
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, er
|
|||||||
Cipher: method,
|
Cipher: method,
|
||||||
Password: password,
|
Password: password,
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
UDP: config.UseUDP,
|
UDP: config.UseUDP,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, e
|
|||||||
Name: remarks,
|
Name: remarks,
|
||||||
ShadowSocksR: P.ShadowSocksR{
|
ShadowSocksR: P.ShadowSocksR{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
Cipher: method,
|
Cipher: method,
|
||||||
Obfs: obfs,
|
Obfs: obfs,
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (p *SocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
|
|||||||
Name: remarks,
|
Name: remarks,
|
||||||
Socks: P.Socks{
|
Socks: P.Socks{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
UserName: username,
|
UserName: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
TLS: tls == "true",
|
TLS: tls == "true",
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (p *TrojanParser) Parse(config ParseConfig, proxy string) (P.Proxy, error)
|
|||||||
insecureBool := insecure == "1"
|
insecureBool := insecure == "1"
|
||||||
result := P.Trojan{
|
result := P.Trojan{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
Password: password,
|
Password: password,
|
||||||
Network: network,
|
Network: network,
|
||||||
UDP: udp == "true",
|
UDP: udp == "true",
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func (p *VlessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
|
|||||||
|
|
||||||
result := P.Vless{
|
result := P.Vless{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
UUID: uuid,
|
UUID: uuid,
|
||||||
Flow: flow,
|
Flow: flow,
|
||||||
UDP: udp == "true",
|
UDP: udp == "true",
|
||||||
|
|||||||
@@ -109,9 +109,9 @@ func (p *VmessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
|
|||||||
|
|
||||||
result := P.Vmess{
|
result := P.Vmess{
|
||||||
Server: vmess.Add,
|
Server: vmess.Add,
|
||||||
Port: port,
|
Port: P.IntOrString(port),
|
||||||
UUID: vmess.Id,
|
UUID: vmess.Id,
|
||||||
AlterID: aid,
|
AlterID: P.IntOrString(aid),
|
||||||
Cipher: vmess.Scy,
|
Cipher: vmess.Scy,
|
||||||
UDP: config.UseUDP,
|
UDP: config.UseUDP,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
<!-- Template -->
|
<!-- Template -->
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
<label for="template">模板链接或名称:</label>
|
<label for="template">模板链接或名称:</label>
|
||||||
<input class="form-control" id="template" name="template" placeholder="输入外部模板链接或内部模板名称(可选)" type="text" />
|
<input class="form-control" id="template" name="template" placeholder="输入模板链接(可选)" type="text" />
|
||||||
</div>
|
</div>
|
||||||
<!-- Subscription Link -->
|
<!-- Subscription Link -->
|
||||||
<div class="form-group mb-3">
|
<div class="form-group mb-3">
|
||||||
|
|||||||
33
test/yaml_test.go
Normal file
33
test/yaml_test.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/bestnite/sub2clash/model/proxy"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testStruct struct {
|
||||||
|
A proxy.IntOrString `yaml:"a"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshal(t *testing.T) {
|
||||||
|
yamlData1 := `a: 123`
|
||||||
|
res := testStruct{}
|
||||||
|
err := yaml.Unmarshal([]byte(yamlData1), &res)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal yaml: %v", err)
|
||||||
|
}
|
||||||
|
if res.A != 123 {
|
||||||
|
t.Errorf("expected 123, but got %v", res.A)
|
||||||
|
}
|
||||||
|
|
||||||
|
yamlData2 := `a: "123"`
|
||||||
|
err = yaml.Unmarshal([]byte(yamlData2), &res)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unmarshal yaml: %v", err)
|
||||||
|
}
|
||||||
|
if res.A != 123 {
|
||||||
|
t.Errorf("expected 123, but got %v", res.A)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user