From 917a33a1905d45d5cb97ef194720b226f098352e Mon Sep 17 00:00:00 2001 From: jebbs Date: Mon, 17 Oct 2022 11:13:26 +0800 Subject: [PATCH] add doc --- docs/configuration/index.md | 1 + docs/configuration/index.zh.md | 1 + docs/configuration/services/index.md | 24 +++++++++ docs/configuration/services/index.zh.md | 24 +++++++++ docs/configuration/services/subscription.md | 52 +++++++++++++++++++ .../configuration/services/subscription.zh.md | 52 +++++++++++++++++++ option/subscription.go | 2 +- service/subscription.go | 5 ++ 8 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 docs/configuration/services/index.md create mode 100644 docs/configuration/services/index.zh.md create mode 100644 docs/configuration/services/subscription.md create mode 100644 docs/configuration/services/subscription.zh.md diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 99fa9ac1..814d8248 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -24,6 +24,7 @@ sing-box uses JSON for configuration files. | `inbounds` | [Inbound](./inbound) | | `outbounds` | [Outbound](./outbound) | | `route` | [Route](./route) | +| `services` | [Services](./services) | | `experimental` | [Experimental](./experimental) | ### Check diff --git a/docs/configuration/index.zh.md b/docs/configuration/index.zh.md index faccf9fa..a00f623a 100644 --- a/docs/configuration/index.zh.md +++ b/docs/configuration/index.zh.md @@ -24,6 +24,7 @@ sing-box 使用 JSON 作为配置文件格式。 | `inbounds` | [入站](./inbound) | | `outbounds` | [出站](./outbound) | | `route` | [路由](./route) | +| `services` | [服务](./services) | | `experimental` | [实验性](./experimental) | ### 检查 diff --git a/docs/configuration/services/index.md b/docs/configuration/services/index.md new file mode 100644 index 00000000..3f6ed0e4 --- /dev/null +++ b/docs/configuration/services/index.md @@ -0,0 +1,24 @@ +# Outbound + +### Structure + +```json +{ + "services": [ + { + "type": "", + "tag": "" + } + ] +} +``` + +### Fields + +| Type | Format | +| -------------- | ------------------------------ | +| `subscription` | [Subscription](./subscription) | + +#### tag + +The tag of the service. \ No newline at end of file diff --git a/docs/configuration/services/index.zh.md b/docs/configuration/services/index.zh.md new file mode 100644 index 00000000..db6c172b --- /dev/null +++ b/docs/configuration/services/index.zh.md @@ -0,0 +1,24 @@ +# 服务 + +### 结构 + +```json +{ + "services": [ + { + "type": "", + "tag": "" + } + ] +} +``` + +### 字段 + +| 类型 | 格式 | +| -------------- | ------------------------------ | +| `subscription` | [Subscription](./subscription) | + +#### tag + +服务的标签。 \ No newline at end of file diff --git a/docs/configuration/services/subscription.md b/docs/configuration/services/subscription.md new file mode 100644 index 00000000..5a1e238a --- /dev/null +++ b/docs/configuration/services/subscription.md @@ -0,0 +1,52 @@ +# Subscription + +### Structure + +```json +{ + "type": "subscription", + "tag": "all.sub", + + "interval": "1h", + "providers": [ + { + "tag": "provider1", + "url": "https://url.to/subscription", + "exclude": "", + "include": "" + } + ] +} +``` + +### Fields + +#### interval + +Refresh interval of the subscription. The minimum value is `1m`, the default value is `1h`. + +#### providers + +List of subscription providers. + +#### providers.tag + +==Required== + +Tag of the subscription provider. + +Suppose we have `node1` from the subscription provider, the tag of the outbound will be `all.sub.provider1.node1`. + +#### providers.url + +==Required== + +URL of the subscription provider. + +#### providers.exclude + +Regular expression to exclude nodes. The priority of the exclude expression is higher than the include expression. + +#### providers.include + +Regular expression to include nodes. diff --git a/docs/configuration/services/subscription.zh.md b/docs/configuration/services/subscription.zh.md new file mode 100644 index 00000000..62ae0029 --- /dev/null +++ b/docs/configuration/services/subscription.zh.md @@ -0,0 +1,52 @@ +# 订阅 + +### 结构 + +```json +{ + "type": "subscription", + "tag": "all.sub", + + "interval": "1h", + "providers": [ + { + "tag": "provider1", + "url": "https://url.to/subscription", + "exclude": "", + "include": "" + } + ] +} +``` + +### 字段 + +#### interval + +刷新订阅的时间间隔。最小值为 `1m`,默认值为 `1h`。 + +#### providers + +订阅源列表。 + +#### providers.tag + +==必填== + +订阅源的标签。 + +所设订阅源中有一个节点 `node1`,则该节点导入后的标签为 `all.sub.provider1.node1`。 + +#### providers.url + +==必填== + +订阅源的 URL。 + +#### providers.exclude + +排除节点的正则表达式。排除表达式的优先级高于包含表达式。 + +#### providers.include + +包含节点的正则表达式。 diff --git a/option/subscription.go b/option/subscription.go index 9cfb1ced..f8cc5dd0 100644 --- a/option/subscription.go +++ b/option/subscription.go @@ -9,7 +9,7 @@ type SubscriptionServiceOptions struct { } type SubscriptionProviderOptions struct { - Tag string `json:"tag,omitempty"` + Tag string `json:"tag"` URL string `json:"url"` Exclude string `json:"exclude,omitempty"` Include string `json:"include,omitempty"` diff --git a/service/subscription.go b/service/subscription.go index 1c92fc04..b533954a 100644 --- a/service/subscription.go +++ b/service/subscription.go @@ -91,7 +91,12 @@ func NewSubscription(ctx context.Context, router adapter.Router, logger log.Cont }) } interval := time.Duration(options.SubscriptionOptions.Interval) + if interval <= 0 { + // default to 1 hour + interval = time.Hour + } if interval < time.Minute { + // minimum interval is 1 minute interval = time.Minute }