1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 20:34:41 -05:00
This commit is contained in:
Nite07 2023-09-17 16:59:02 +08:00
parent 4f4a633035
commit 354379b12a
4 changed files with 24 additions and 13 deletions

View File

@ -5,3 +5,4 @@ REQUEST_RETRY_TIMES=3
REQUEST_MAX_FILE_SIZE=1048576
CACHE_EXPIRE=300
LOG_LEVEL=info
BASE_PATH=/

View File

@ -26,7 +26,8 @@
可以通过编辑 .env 文件来修改默认配置docker 直接添加环境变量
| 变量名 | 说明 | 默认值 |
|-----------------------|----------------------------------------|-----------------------|
|-----------------------|-----------------------------------------------------------|-----------------------|
| BASE_PATH | 程序运行子路径,例如将服务反代在 `https://example.com/sub` 则此变量值应为 `/sub` | `/` |
| PORT | 端口 | `8011` |
| META_TEMPLATE | meta 模板文件名 | `template_meta.yaml` |
| CLASH_TEMPLATE | clash 模板文件名 | `template_clash.yaml` |
@ -63,5 +64,3 @@
[代理链接解析](./parser)还没有经过严格测试,可能会出现解析错误的情况,如果出现问题请提交 issue
## TODO
- [x] 可视化面板

View File

@ -4,6 +4,8 @@ import (
"crypto/sha256"
"encoding/hex"
"github.com/gin-gonic/gin"
"net/http"
"sub2clash/config"
"sub2clash/model"
"sub2clash/utils/database"
"sub2clash/validator"
@ -46,5 +48,6 @@ func ShortLinkGetHandler(c *gin.Context) {
c.String(404, "未找到短链接")
return
}
c.Redirect(302, "../"+shortLink.Url)
uri := config.Default.BasePath + shortLink.Url
c.Redirect(http.StatusTemporaryRedirect, uri)
}

View File

@ -14,6 +14,7 @@ type Config struct {
RequestMaxFileSize int64
CacheExpire int64
LogLevel string
BasePath string
}
var Default *Config
@ -27,6 +28,7 @@ func init() {
Port: 8011,
CacheExpire: 60 * 5,
LogLevel: "info",
BasePath: "/",
}
err := godotenv.Load()
if err != nil {
@ -69,4 +71,10 @@ func init() {
if os.Getenv("LOG_LEVEL") != "" {
Default.LogLevel = os.Getenv("LOG_LEVEL")
}
if os.Getenv("BASE_PATH") != "" {
Default.BasePath = os.Getenv("BASE_PATH")
if Default.BasePath[len(Default.BasePath)-1] != '/' {
Default.BasePath += "/"
}
}
}