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

Reordered import statements across multiple files

for consistency
This commit is contained in:
Nite07 2023-11-03 02:35:30 +08:00
parent d0696aad5b
commit 73e94ad856
23 changed files with 10454 additions and 10394 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 配置链接
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|--------------|--------|-------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------ | ------ | ------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
| sub | string | sub/proxy 至少有一项存在 | - | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个,用 `,` 分隔) |
| proxy | string | sub/proxy 至少有一项存在 | - | 节点分享链接(可以输入多个,用 `,` 分隔) |
| refresh | bool | 否 | `false` | 强制刷新配置(默认缓存 5 分钟) |
@ -23,7 +23,7 @@
具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
| Body 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|----------|--------|------|-----|------------------|
| --------- | ------ | -------- | ------ | ------------------------- |
| url | string | 是 | - | 需要转换的 Query 参数部分 |
| password | string | 否 | - | 短链密码 |
@ -33,5 +33,5 @@
`hash` 为动态路由参数,可以通过 `/short` 接口获取
| Query 参数 | 类型 | 是否必须 | 默认值 | 说明 |
|----------|--------|------|-----|------|
| ---------- | ------ | -------- | ------ | -------- |
| password | string | 否 | - | 短链密码 |

View File

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

View File

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

View File

@ -4,8 +4,6 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
"net/url"
"regexp"
"sort"
@ -16,6 +14,9 @@ import (
"sub2clash/parser"
"sub2clash/utils"
"sub2clash/validator"
"go.uber.org/zap"
"gopkg.in/yaml.v3"
)
func BuildSub(clashType model.ClashType, query validator.SubValidator, template string) (

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
@ -117,7 +117,9 @@
name="refresh"
type="checkbox"
/>
<label class="form-check-label" for="refresh">强制重新获取订阅</label>
<label class="form-check-label" for="refresh"
>强制重新获取订阅</label
>
</div>
<!-- Node List -->
<div class="form-check mb-3">
@ -127,7 +129,9 @@
name="nodeList"
type="checkbox"
/>
<label class="form-check-label" for="nodeList">输出为 Node List</label>
<label class="form-check-label" for="nodeList"
>输出为 Node List</label
>
</div>
<!-- Auto Test -->
<div class="form-check mb-3">
@ -143,7 +147,12 @@
</div>
<!-- Lazy -->
<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"
>自动测速启用 lazy 模式</label
>
@ -207,8 +216,17 @@
<div class="form-group mb-5">
<label for="apiLink">配置链接:</label>
<div class="input-group mb-2">
<input class="form-control" id="apiLink" readonly type="text" />
<button class="btn btn-primary" onclick="generateURL()" type="button">
<input
class="form-control"
id="apiLink"
readonly
type="text"
/>
<button
class="btn btn-primary"
onclick="generateURL()"
type="button"
>
生成链接
</button>
<button
@ -220,7 +238,12 @@
</button>
</div>
<div class="input-group">
<input class="form-control" id="apiShortLink" readonly type="text" />
<input
class="form-control"
id="apiShortLink"
readonly
type="text"
/>
<input
class="form-control"
id="password"
@ -247,7 +270,9 @@
<footer>
<p class="text-center">
Powered by
<a class="link-primary" href="https://github.com/nitezs/sub2clash"
<a
class="link-primary"
href="https://github.com/nitezs/sub2clash"
>sub2clash</a
>
</p>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -45,6 +45,7 @@ func ParseHysteria2(proxy string) (model.Proxy, error) {
Obfs: params.Get("obfs"),
ObfsParam: params.Get("obfs-password"),
Sni: params.Get("sni"),
SkipCertVerify: params.Get("insecure") == "1",
}
return result, nil
}

View File

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

View File

@ -1,11 +1,12 @@
package utils
import (
"go.uber.org/zap"
"strings"
"sub2clash/logger"
"sub2clash/model"
"sub2clash/parser"
"go.uber.org/zap"
)
func GetContryName(countryKey string) string {

View File

@ -4,11 +4,12 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"github.com/gin-gonic/gin"
"net/url"
"os"
"regexp"
"strings"
"github.com/gin-gonic/gin"
)
type SubValidator struct {