1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-24 11:44:42 -05:00

Merge pull request #14 from nitezs/dev

Dev
This commit is contained in:
Nite07 2024-02-19 13:12:12 +08:00 committed by GitHub
commit 3309a0c208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 10493 additions and 10327 deletions

13
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"configurations": [
{
"name": "Debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"output": "${workspaceFolder}/dist/main.exe",
"buildFlags": "-ldflags '-X sub2clash/config.Dev=true -X sub2clash/config.Version=dev'"
}
]
}

View File

@ -3,7 +3,7 @@
获取 Clash/Clash.Meta 配置链接 获取 Clash/Clash.Meta 配置链接
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 | | Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|--------------|--------|-------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |--------------|--------|-------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| sub | string | sub/proxy 至少有一项存在 | - | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个,用 `,` 分隔) | | sub | string | sub/proxy 至少有一项存在 | - | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个,用 `,` 分隔) |
| proxy | string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个,用 `,` 分隔) | | proxy | string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个,用 `,` 分隔) |
| refresh | bool | 否 | `false` | 强制刷新配置(默认缓存 5 分钟) | | refresh | bool | 否 | `false` | 强制刷新配置(默认缓存 5 分钟) |
@ -15,7 +15,7 @@
| sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` | | sort | string | 否 | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc` |
| replace | string | 否 | - | 通过正则表达式重命名节点,格式 `[<ReplaceKey>,<ReplaceTo>],[<ReplaceKey>,<ReplaceTo>]...` | | replace | string | 否 | - | 通过正则表达式重命名节点,格式 `[<ReplaceKey>,<ReplaceTo>],[<ReplaceKey>,<ReplaceTo>]...` |
| remove | string | 否 | - | 通过正则表达式删除节点 | | remove | string | 否 | - | 通过正则表达式删除节点 |
| nodeList | bool | 否 | `false` | 只输出节点 | | | nodeList | bool | 否 | `false` | 只输出节点 |
# `/short` # `/short`

View File

@ -1,18 +1,21 @@
# sub2clash # sub2clash
将订阅链接转换为 Clash、Clash.Meta 配置 将订阅链接转换为 Clash、Clash.Meta 配置
[预览](https://www.nite07.com/sub)
## 特性 ## 特性
- 开箱即用的规则、策略组配置 - 开箱即用的规则、策略组配置
- 自动根据节点名称按国家划分策略组 - 自动根据节点名称按国家划分策略组
- 支持多订阅合并 - 支持多订阅合并
- 支持添加自定义 Rule Provider、Rule
- 支持多种协议 - 支持多种协议
- Shadowsocks - Shadowsocks
- ShadowsocksR - ShadowsocksR
- Vmess - Vmess
- Vless - Vless Clash.Meta
- Trojan - Trojan
- Hysteria2 Clash.Meta
## 使用 ## 使用
@ -26,10 +29,10 @@
可以通过编辑 .env 文件来修改默认配置docker 直接添加环境变量 可以通过编辑 .env 文件来修改默认配置docker 直接添加环境变量
| 变量名 | 说明 | 默认值 | | 变量名 | 说明 | 默认值 |
|-----------------------|-----------------------------------------------------------|-----------------------| |-----------------------|----------------------------------------|-----------------------|
| PORT | 端口 | `8011` | | PORT | 端口 | `8011` |
| META_TEMPLATE | meta 模板文件名 | `template_meta.yaml` | | META_TEMPLATE | 默认 meta 模板文件名 | `template_meta.yaml` |
| CLASH_TEMPLATE | clash 模板文件名 | `template_clash.yaml` | | CLASH_TEMPLATE | 默认 clash 模板文件名 | `template_clash.yaml` |
| REQUEST_RETRY_TIMES | Get 请求重试次数 | `3` | | REQUEST_RETRY_TIMES | Get 请求重试次数 | `3` |
| REQUEST_MAX_FILE_SIZE | Get 请求订阅文件最大大小byte | `1048576` | | REQUEST_MAX_FILE_SIZE | Get 请求订阅文件最大大小byte | `1048576` |
| CACHE_EXPIRE | 订阅缓存时间(秒) | `300` | | CACHE_EXPIRE | 订阅缓存时间(秒) | `300` |

View File

@ -1,12 +1,13 @@
package controller package controller
import ( import (
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
"net/http" "net/http"
"sub2clash/config" "sub2clash/config"
"sub2clash/model" "sub2clash/model"
"sub2clash/validator" "sub2clash/validator"
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
) )
func SubmodHandler(c *gin.Context) { func SubmodHandler(c *gin.Context) {

View File

@ -4,8 +4,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors" "errors"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"net/url" "net/url"
"regexp" "regexp"
"sort" "sort"
@ -16,6 +14,9 @@ import (
"sub2clash/parser" "sub2clash/parser"
"sub2clash/utils" "sub2clash/utils"
"sub2clash/validator" "sub2clash/validator"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
) )
func BuildSub(clashType model.ClashType, query validator.SubValidator, template string) ( func BuildSub(clashType model.ClashType, query validator.SubValidator, template string) (
@ -30,9 +31,8 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
if query.Template != "" { if query.Template != "" {
template = query.Template template = query.Template
} }
_, err = url.ParseRequestURI(template) if strings.HasPrefix(template, "http") {
if err != nil { templateBytes, err = utils.LoadSubscription(template, query.Refresh)
templateBytes, err = utils.LoadTemplate(template)
if err != nil { if err != nil {
logger.Logger.Debug( logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err), "load template failed", zap.String("template", template), zap.Error(err),
@ -40,7 +40,11 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
return nil, errors.New("加载模板失败: " + err.Error()) return nil, errors.New("加载模板失败: " + err.Error())
} }
} else { } else {
templateBytes, err = utils.LoadSubscription(template, query.Refresh) unescape, err := url.QueryUnescape(template)
if err != nil {
return nil, errors.New("加载模板失败: " + err.Error())
}
templateBytes, err = utils.LoadTemplate(unescape)
if err != nil { if err != nil {
logger.Logger.Debug( logger.Logger.Debug(
"load template failed", zap.String("template", template), zap.Error(err), "load template failed", zap.String("template", template), zap.Error(err),
@ -72,7 +76,7 @@ func BuildSub(clashType model.ClashType, query validator.SubValidator, template
err = yaml.Unmarshal(data, &sub) err = yaml.Unmarshal(data, &sub)
newProxies := make([]model.Proxy, 0) newProxies := make([]model.Proxy, 0)
if err != nil { if err != nil {
reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless)://") reg, _ := regexp.Compile("(ssr|ss|vmess|trojan|vless|hysteria)://")
if reg.Match(data) { if reg.Match(data) {
p := utils.ParseProxy(strings.Split(string(data), "\n")...) p := utils.ParseProxy(strings.Split(string(data), "\n")...)
newProxies = p newProxies = p

View File

@ -2,12 +2,13 @@ package controller
import ( import (
_ "embed" _ "embed"
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
"net/http" "net/http"
"sub2clash/config" "sub2clash/config"
"sub2clash/model" "sub2clash/model"
"sub2clash/validator" "sub2clash/validator"
"github.com/gin-gonic/gin"
"gopkg.in/yaml.v3"
) )
func SubHandler(c *gin.Context) { func SubHandler(c *gin.Context) {

View File

@ -2,9 +2,6 @@ package controller
import ( import (
"errors" "errors"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"gorm.io/gorm"
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
@ -16,6 +13,10 @@ import (
"sub2clash/utils/database" "sub2clash/utils/database"
"sub2clash/validator" "sub2clash/validator"
"time" "time"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"gorm.io/gorm"
) )
func ShortLinkGenHandler(c *gin.Context) { func ShortLinkGenHandler(c *gin.Context) {

View File

@ -2,13 +2,14 @@ package api
import ( import (
"embed" "embed"
"github.com/gin-gonic/gin"
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
"sub2clash/api/controller" "sub2clash/api/controller"
"sub2clash/config" "sub2clash/config"
"sub2clash/middleware" "sub2clash/middleware"
"github.com/gin-gonic/gin"
) )
//go:embed static //go:embed static

View File

@ -1,4 +1,4 @@
<!doctype html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
@ -46,6 +46,8 @@
target="_blank" target="_blank"
>使用文档</a >使用文档</a
></span ></span
><br><span class="text-muted fst-italic"
>注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点</span
> >
</div> </div>
@ -117,7 +119,9 @@
name="refresh" name="refresh"
type="checkbox" type="checkbox"
/> />
<label class="form-check-label" for="refresh">强制重新获取订阅</label> <label class="form-check-label" for="refresh"
>强制重新获取订阅</label
>
</div> </div>
<!-- Node List --> <!-- Node List -->
<div class="form-check mb-3"> <div class="form-check mb-3">
@ -127,7 +131,9 @@
name="nodeList" name="nodeList"
type="checkbox" type="checkbox"
/> />
<label class="form-check-label" for="nodeList">输出为 Node List</label> <label class="form-check-label" for="nodeList"
>输出为 Node List</label
>
</div> </div>
<!-- Auto Test --> <!-- Auto Test -->
<div class="form-check mb-3"> <div class="form-check mb-3">
@ -143,7 +149,12 @@
</div> </div>
<!-- Lazy --> <!-- Lazy -->
<div class="form-check mb-3"> <div class="form-check mb-3">
<input class="form-check-input" id="lazy" name="lazy" type="checkbox" /> <input
class="form-check-input"
id="lazy"
name="lazy"
type="checkbox"
/>
<label class="form-check-label" for="lazy" <label class="form-check-label" for="lazy"
>自动测速启用 lazy 模式</label >自动测速启用 lazy 模式</label
> >
@ -207,8 +218,17 @@
<div class="form-group mb-5"> <div class="form-group mb-5">
<label for="apiLink">配置链接:</label> <label for="apiLink">配置链接:</label>
<div class="input-group mb-2"> <div class="input-group mb-2">
<input class="form-control" id="apiLink" readonly type="text" /> <input
<button class="btn btn-primary" onclick="generateURL()" type="button"> class="form-control"
id="apiLink"
readonly
type="text"
/>
<button
class="btn btn-primary"
onclick="generateURL()"
type="button"
>
生成链接 生成链接
</button> </button>
<button <button
@ -220,7 +240,12 @@
</button> </button>
</div> </div>
<div class="input-group"> <div class="input-group">
<input class="form-control" id="apiShortLink" readonly type="text" /> <input
class="form-control"
id="apiShortLink"
readonly
type="text"
/>
<input <input
class="form-control" class="form-control"
id="password" id="password"
@ -247,7 +272,9 @@
<footer> <footer>
<p class="text-center"> <p class="text-center">
Powered by Powered by
<a class="link-primary" href="https://github.com/nitezs/sub2clash" <a
class="link-primary"
href="https://github.com/nitezs/sub2clash"
>sub2clash</a >sub2clash</a
> >
</p> </p>

View File

@ -114,7 +114,11 @@ function generateURI() {
let prepend = rules[i * 3 + 1].value; let prepend = rules[i * 3 + 1].value;
let group = rules[i * 3 + 2].value; let group = rules[i * 3 + 2].value;
// 是否存在空值 // 是否存在空值
if (rule.trim() === "" || prepend.trim() === "" || group.trim() === "") { if (
rule.trim() === "" ||
prepend.trim() === "" ||
group.trim() === ""
) {
alert("Rule 中存在空值,请检查后重试!"); alert("Rule 中存在空值,请检查后重试!");
return ""; return "";
} }
@ -189,14 +193,16 @@ function parseInputURL() {
} }
if (params.has("sub")) { if (params.has("sub")) {
document.getElementById("sub").value = decodeURIComponent(params.get("sub")) document.getElementById("sub").value = decodeURIComponent(
params.get("sub")
)
.split(",") .split(",")
.join("\n"); .join("\n");
} }
if (params.has("proxy")) { if (params.has("proxy")) {
document.getElementById("proxy").value = decodeURIComponent( document.getElementById("proxy").value = decodeURIComponent(
params.get("proxy"), params.get("proxy")
) )
.split(",") .split(",")
.join("\n"); .join("\n");
@ -218,7 +224,7 @@ function parseInputURL() {
if (params.has("template")) { if (params.has("template")) {
document.getElementById("template").value = decodeURIComponent( document.getElementById("template").value = decodeURIComponent(
params.get("template"), params.get("template")
); );
} }
@ -228,7 +234,7 @@ function parseInputURL() {
if (params.has("remove")) { if (params.has("remove")) {
document.getElementById("remove").value = decodeURIComponent( document.getElementById("remove").value = decodeURIComponent(
params.get("remove"), params.get("remove")
); );
} }
@ -238,7 +244,7 @@ function parseInputURL() {
if (params.has("ruleProvider")) { if (params.has("ruleProvider")) {
parseAndFillRuleProviderParams( parseAndFillRuleProviderParams(
decodeURIComponent(params.get("ruleProvider")), decodeURIComponent(params.get("ruleProvider"))
); );
} }
@ -403,7 +409,7 @@ function generateShortLink() {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}, }
) )
.then((response) => { .then((response) => {
apiShortLink.value = `${window.location.origin}${window.location.pathname}s/${response.data}`; apiShortLink.value = `${window.location.origin}${window.location.pathname}s/${response.data}`;

View File

@ -2,9 +2,10 @@ package config
import ( import (
"errors" "errors"
"github.com/joho/godotenv"
"os" "os"
"strconv" "strconv"
"github.com/joho/godotenv"
) )
type Config struct { type Config struct {

View File

@ -1,4 +1,4 @@
version: '3' version: "3"
services: services:
sub2clash: sub2clash:

View File

@ -1,11 +1,12 @@
package logger package logger
import ( import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"path/filepath" "path/filepath"
"sync" "sync"
"time" "time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
) )
var ( var (

View File

@ -2,8 +2,6 @@ package main
import ( import (
_ "embed" _ "embed"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"io" "io"
"strconv" "strconv"
"sub2clash/api" "sub2clash/api"
@ -11,6 +9,9 @@ import (
"sub2clash/logger" "sub2clash/logger"
"sub2clash/utils" "sub2clash/utils"
"sub2clash/utils/database" "sub2clash/utils/database"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
) )
//go:embed templates/template_meta.yaml //go:embed templates/template_meta.yaml

View File

@ -1,11 +1,12 @@
package middleware package middleware
import ( import (
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"strconv" "strconv"
"sub2clash/logger" "sub2clash/logger"
"time" "time"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
) )
func ZapLogger() gin.HandlerFunc { func ZapLogger() gin.HandlerFunc {

View File

@ -23,6 +23,7 @@ func GetSupportProxyTypes(clashType ClashType) map[string]bool {
"vmess": true, "vmess": true,
"trojan": true, "trojan": true,
"vless": true, "vless": true,
"hysteria2": true,
} }
} }
return nil return nil

View File

@ -45,6 +45,11 @@ type Proxy struct {
UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"` UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"`
UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"` UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"`
SubName string `yaml:"-"` SubName string `yaml:"-"`
Up string `yaml:"up,omitempty"`
Down string `yaml:"down,omitempty"`
CustomCA string `yaml:"ca,omitempty"`
CustomCAString string `yaml:"ca-str,omitempty"`
CWND int `yaml:"cwnd,omitempty"`
} }
func (p Proxy) MarshalYAML() (interface{}, error) { func (p Proxy) MarshalYAML() (interface{}, error) {
@ -59,6 +64,8 @@ func (p Proxy) MarshalYAML() (interface{}, error) {
return ProxyToVless(p), nil return ProxyToVless(p), nil
case "trojan": case "trojan":
return ProxyToTrojan(p), nil return ProxyToTrojan(p), nil
case "hysteria2":
return ProxyToHysteria2(p), nil
} }
return nil, nil return nil, nil
} }

41
model/proxy_hysteria2.go Normal file
View File

@ -0,0 +1,41 @@
package model
type Hysteria2 struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Server string `yaml:"server"`
Port int `yaml:"port"`
Up string `yaml:"up,omitempty"`
Down string `yaml:"down,omitempty"`
Password string `yaml:"password,omitempty"`
Obfs string `yaml:"obfs,omitempty"`
ObfsPassword string `yaml:"obfs-password,omitempty"`
SNI string `yaml:"sni,omitempty"`
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
Fingerprint string `yaml:"fingerprint,omitempty"`
ALPN []string `yaml:"alpn,omitempty"`
CustomCA string `yaml:"ca,omitempty"`
CustomCAString string `yaml:"ca-str,omitempty"`
CWND int `yaml:"cwnd,omitempty"`
}
func ProxyToHysteria2(p Proxy) Hysteria2 {
return Hysteria2{
Type: "hysteria2",
Name: p.Name,
Server: p.Server,
Port: p.Port,
Up: p.Up,
Down: p.Down,
Password: p.Password,
Obfs: p.Obfs,
ObfsPassword: p.ObfsParam,
SNI: p.Sni,
SkipCertVerify: p.SkipCertVerify,
Fingerprint: p.Fingerprint,
ALPN: p.Alpn,
CustomCA: p.CustomCA,
CustomCAString: p.CustomCAString,
CWND: p.CWND,
}
}

View File

@ -16,8 +16,8 @@ type GrpcOptions struct {
} }
type RealityOptions struct { type RealityOptions struct {
PublicKey string `proxy:"public-key"` PublicKey string `yaml:"public-key"`
ShortID string `proxy:"short-id"` ShortID string `yaml:"short-id,omitempty"`
} }
type WSOptions struct { type WSOptions struct {

51
parser/hysteria2.go Normal file
View File

@ -0,0 +1,51 @@
package parser
import (
"errors"
"net/url"
"strconv"
"strings"
"sub2clash/model"
)
func ParseHysteria2(proxy string) (model.Proxy, error) {
// 判断是否以 hysteria2:// 开头
if !strings.HasPrefix(proxy, "hysteria2://") {
return model.Proxy{}, errors.New("invalid hysteria2 Url")
}
// 分割
parts := strings.SplitN(strings.TrimPrefix(proxy, "hysteria2://"), "@", 2)
if len(parts) != 2 {
return model.Proxy{}, errors.New("invalid hysteria2 Url")
}
// 分割
serverInfo := strings.SplitN(parts[1], "/?", 2)
serverAndPort := strings.SplitN(serverInfo[0], ":", 2)
if len(serverAndPort) == 1 {
serverAndPort = append(serverAndPort, "443")
} else if len(serverAndPort) != 2 {
return model.Proxy{}, errors.New("invalid hysteria2 Url")
}
params, err := url.ParseQuery(serverInfo[1])
if err != nil {
return model.Proxy{}, errors.New("invalid hysteria2 Url")
}
// 获取端口
port, err := strconv.Atoi(serverAndPort[1])
if err != nil {
return model.Proxy{}, errors.New("invalid hysteria2 Url")
}
// 返回结果
result := model.Proxy{
Type: "hysteria2",
Name: params.Get("name"),
Server: serverAndPort[0],
Port: port,
Password: parts[0],
Obfs: params.Get("obfs"),
ObfsParam: params.Get("obfs-password"),
Sni: params.Get("sni"),
SkipCertVerify: params.Get("insecure") == "1",
}
return result, nil
}

View File

@ -43,9 +43,9 @@ func ParseVless(proxy string) (model.Proxy, error) {
UDP: true, UDP: true,
Sni: params.Get("sni"), Sni: params.Get("sni"),
Network: params.Get("type"), Network: params.Get("type"),
TLS: params.Get("security") == "tls", TLS: params.Get("security") == "reality",
Flow: params.Get("flow"), Flow: params.Get("flow"),
Fingerprint: params.Get("fp"), ClientFingerprint: params.Get("fp"),
Servername: params.Get("sni"), Servername: params.Get("sni"),
RealityOpts: model.RealityOptions{ RealityOpts: model.RealityOptions{
PublicKey: params.Get("pbk"), PublicKey: params.Get("pbk"),

View File

@ -1,13 +1,14 @@
package database package database
import ( import (
"github.com/glebarez/sqlite"
"go.uber.org/zap"
"gorm.io/gorm"
"path/filepath" "path/filepath"
"sub2clash/logger" "sub2clash/logger"
"sub2clash/model" "sub2clash/model"
"sub2clash/utils" "sub2clash/utils"
"github.com/glebarez/sqlite"
"go.uber.org/zap"
"gorm.io/gorm"
) )
var DB *gorm.DB var DB *gorm.DB

View File

@ -1,11 +1,12 @@
package utils package utils
import ( import (
"go.uber.org/zap"
"strings" "strings"
"sub2clash/logger" "sub2clash/logger"
"sub2clash/model" "sub2clash/model"
"sub2clash/parser" "sub2clash/parser"
"go.uber.org/zap"
) )
func GetContryName(countryKey string) string { func GetContryName(countryKey string) string {
@ -126,6 +127,9 @@ func ParseProxy(proxies ...string) []model.Proxy {
if strings.HasPrefix(proxy, "ssr://") { if strings.HasPrefix(proxy, "ssr://") {
proxyItem, err = parser.ParseShadowsocksR(proxy) proxyItem, err = parser.ParseShadowsocksR(proxy)
} }
if strings.HasPrefix(proxy, "hysteria2://") {
proxyItem, err = parser.ParseHysteria2(proxy)
}
if err == nil { if err == nil {
result = append(result, proxyItem) result = append(result, proxyItem)
} else { } else {

View File

@ -4,11 +4,11 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"errors" "errors"
"github.com/gin-gonic/gin"
"net/url" "net/url"
"os"
"regexp" "regexp"
"strings" "strings"
"github.com/gin-gonic/gin"
) )
type SubValidator struct { type SubValidator struct {
@ -72,14 +72,14 @@ func ParseQuery(c *gin.Context) (SubValidator, error) {
query.Proxies = nil query.Proxies = nil
} }
if query.Template != "" { if query.Template != "" {
if strings.HasPrefix(query.Template, "http") {
uri, err := url.ParseRequestURI(query.Template) uri, err := url.ParseRequestURI(query.Template)
if err != nil { if err != nil {
if strings.Contains(query.Template, string(os.PathSeparator)) {
return SubValidator{}, err return SubValidator{}, err
} }
}
query.Template = uri.String() query.Template = uri.String()
} }
}
if query.RuleProvider != "" { if query.RuleProvider != "" {
reg := regexp.MustCompile(`\[(.*?)\]`) reg := regexp.MustCompile(`\[(.*?)\]`)
ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1) ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1)