Compare commits
152 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09163ed4df | ||
|
|
f5c32915b9 | ||
|
|
286fa0f311 | ||
|
|
5d08993cbc | ||
|
|
6e787ced6e | ||
|
|
460b7514a9 | ||
|
|
c90140a898 | ||
|
|
f7e4fe71d7 | ||
|
|
33973b786d | ||
|
|
36fe815e35 | ||
|
|
c393191b93 | ||
|
|
beb441f0b0 | ||
|
|
c45adfb915 | ||
|
|
102dc00b27 | ||
|
|
b0042397c9 | ||
|
|
70b46c0fb2 | ||
|
|
5258046faa | ||
|
|
eddd37a59c | ||
|
|
7a57317a8b | ||
|
|
6f95e1c182 | ||
|
|
31b0b72450 | ||
|
|
00ae38753e | ||
|
|
2aa665d89a | ||
|
|
17a2ba173d | ||
|
|
a0e5846e11 | ||
|
|
972baee564 | ||
|
|
a281d4c779 | ||
|
|
e4252d0596 | ||
|
|
de65889a4d | ||
|
|
90b9c69dad | ||
|
|
acd38f4fe0 | ||
|
|
83e6b78a93 | ||
|
|
8371f9564f | ||
|
|
546a8ca981 | ||
|
|
be6314bd53 | ||
|
|
28331e9ec5 | ||
|
|
51f179f9e9 | ||
|
|
33eb0e2d34 | ||
|
|
9bfca20d11 | ||
|
|
ede418420d | ||
|
|
243172c988 | ||
|
|
a8d2b0700c | ||
|
|
891ce86101 | ||
|
|
1bf4eca13d | ||
|
|
e01028df08 | ||
|
|
708f25c02b | ||
|
|
31678b243c | ||
|
|
0944b81dcb | ||
|
|
723b849ee0 | ||
|
|
a537c09491 | ||
|
|
6f050d38ac | ||
|
|
d8c57b7191 | ||
|
|
a77f265a17 | ||
|
|
7b9a18225a | ||
|
|
44105fc0cf | ||
|
|
3d742960cc | ||
|
|
0fb7ee3679 | ||
|
|
efe734d976 | ||
|
|
890dc067b9 | ||
|
|
a43f1f20f6 | ||
|
|
e59c118475 | ||
|
|
d1f862e799 | ||
|
|
d5e3b7fc23 | ||
|
|
8dea98f795 | ||
|
|
b1a60017e4 | ||
|
|
96bd4a2c18 | ||
|
|
43c576bd82 | ||
|
|
580865d082 | ||
|
|
c2af045019 | ||
|
|
d297f785db | ||
|
|
f6f1ff7362 | ||
|
|
920b025fda | ||
|
|
59428e47aa | ||
|
|
e3f9a0d4c6 | ||
|
|
a14202f75d | ||
|
|
9d59731afe | ||
|
|
784407b2dd | ||
|
|
32fcc1071f | ||
|
|
32584f9516 | ||
|
|
0ce5c2c11c | ||
|
|
1bfb2af51d | ||
|
|
6bd4a84dc1 | ||
|
|
06dc764063 | ||
|
|
c55ae4a5b7 | ||
|
|
85896ffbfe | ||
|
|
4397bc2cf9 | ||
|
|
3ea6d34fb2 | ||
|
|
391c4b3594 | ||
|
|
0ab01a9b83 | ||
|
|
8787c11e06 | ||
|
|
06191e52e5 | ||
|
|
2113205123 | ||
|
|
67a006df0f | ||
|
|
45b99393e6 | ||
|
|
b6c4dbbf9c | ||
|
|
d9cc088dce | ||
|
|
723ab6c3e9 | ||
|
|
11ba7cb0e5 | ||
|
|
f1ff3e9d27 | ||
|
|
b1e3a9c1bd | ||
|
|
267dfafcb9 | ||
|
|
e32adadaff | ||
|
|
942dda86e7 | ||
|
|
bbfc7c0d6d | ||
|
|
5af898b3e6 | ||
|
|
3c162bf9d7 | ||
|
|
1eed79463d | ||
|
|
6f67f6f5b4 | ||
|
|
2a5570a447 | ||
|
|
eb45ab8798 | ||
|
|
2b7e949658 | ||
|
|
fe652821bd | ||
|
|
92b3e19954 | ||
|
|
19f753a515 | ||
|
|
157cbf9d3a | ||
|
|
f80782b803 | ||
|
|
b1c8658a1c | ||
|
|
57cd7e1ce7 | ||
|
|
29046382a5 | ||
|
|
2355447f97 | ||
|
|
8187464007 | ||
|
|
575e36ef90 | ||
|
|
c31e887ad3 | ||
|
|
b633bec69b | ||
|
|
052827bca7 | ||
|
|
0c1eb34e49 | ||
|
|
3489e6d744 | ||
|
|
a8af0fb687 | ||
|
|
c0af779642 | ||
|
|
d7949f625a | ||
|
|
ddd12729a4 | ||
|
|
91b7cfe533 | ||
|
|
aee81ba4fd | ||
|
|
e5d941414e | ||
|
|
c50f23c399 | ||
|
|
47d062a1c4 | ||
|
|
57ba06e01e | ||
|
|
52fdaf5f81 | ||
|
|
d6b8f2b812 | ||
|
|
00d2113904 | ||
|
|
670bca31ca | ||
|
|
f77de0d37a | ||
|
|
1c18ccc363 | ||
|
|
a386304d42 | ||
|
|
1b5b34d265 | ||
|
|
505c2e559e | ||
|
|
dd9a0c8adb | ||
|
|
f4cb77a72e | ||
|
|
4155b9cf4f | ||
|
|
00538f3d91 | ||
|
|
1fd1e3bc2a | ||
|
|
b83c242416 |
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: 报告问题与漏洞
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### 问题描述
|
||||
|
||||
请简要描述发现的问题是什么,以及如何重现。
|
||||
|
||||
### 复现步骤
|
||||
|
||||
1. 打开...
|
||||
2. 点击...
|
||||
3. 观察到...
|
||||
|
||||
### 预期行为
|
||||
|
||||
请描述在正常情况下应该发生什么。
|
||||
|
||||
### 实际行为
|
||||
|
||||
请描述实际发生了什么。
|
||||
|
||||
### 截图
|
||||
|
||||
如果适用,请添加截图以帮助解释您的问题。
|
||||
|
||||
### 环境信息
|
||||
|
||||
- 发行版: [例如 Debian12, Alpine-Edge ]
|
||||
- 部署方式: [可执行文件/Docker ]
|
||||
- GHProxy版本: [例如 1.0.0]
|
||||
|
||||
### 附加信息
|
||||
|
||||
请提供任何其他可能有助于我们解决问题的信息。
|
||||
20
.github/ISSUE_TEMPLATE/features_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/features_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Features request
|
||||
about: 提出新功能建议
|
||||
title: "[Features]"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### 功能描述
|
||||
|
||||
请简要描述您希望增加的功能。
|
||||
|
||||
### 功能原因
|
||||
|
||||
请说明您为什么需要这个功能。
|
||||
|
||||
### 功能实现
|
||||
|
||||
请详细描述您期望的功能实现。
|
||||
2
.github/dependabot.yml
vendored
2
.github/dependabot.yml
vendored
@@ -8,4 +8,4 @@ updates:
|
||||
- package-ecosystem: "gomod" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
interval: "daily"
|
||||
|
||||
86
.github/workflows/build-dev.yml
vendored
86
.github/workflows/build-dev.yml
vendored
@@ -4,52 +4,83 @@ on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'dev'
|
||||
paths:
|
||||
- 'DEV-VERSION'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
prepare:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [linux]
|
||||
goarch: [amd64, arm64]
|
||||
env:
|
||||
OUTPUT_BINARY: ghproxy
|
||||
GO_VERSION: 1.23.2
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Load VERSION
|
||||
- name: 加载版本号
|
||||
run: |
|
||||
if [ -f DEV-VERSION ]; then
|
||||
echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "DEV-VERSION file not found!" && exit 1
|
||||
fi
|
||||
- name: Set up Go
|
||||
- name: 输出版本号
|
||||
run: |
|
||||
echo "Version: ${{ env.VERSION }}"
|
||||
- name: 预先创建Pre-release
|
||||
id: create_release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ env.VERSION }}
|
||||
artifacts: ./DEV-VERSION
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ env.VERSION }}
|
||||
allowUpdates: true
|
||||
prerelease: true
|
||||
body: ${{ env.VERSION }}
|
||||
env:
|
||||
export PATH: $PATH:/usr/local/go/bin
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [linux, darwin, freebsd]
|
||||
goarch: [amd64, arm64]
|
||||
env:
|
||||
OUTPUT_BINARY: ghproxy
|
||||
GO_VERSION: 1.23.6
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: dev
|
||||
- name: 加载版本号
|
||||
run: |
|
||||
if [ -f DEV-VERSION ]; then
|
||||
echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "DEV-VERSION file not found!" && exit 1
|
||||
fi
|
||||
- name: 安装 Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: Install UPX
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install upx -y
|
||||
- name: Build
|
||||
- name: 编译
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
run: |
|
||||
CGO_ENABLED=0 go build -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go
|
||||
upx -9 ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
- name: Package
|
||||
CGO_ENABLED=0 go build -ldflags "-X main.version=${{ env.VERSION }} -X main.dev=true" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go
|
||||
- name: 打包
|
||||
run: |
|
||||
tar -czvf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
- name: Upload to GitHub Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
mkdir ghproxyd
|
||||
cp ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./ghproxyd/
|
||||
mv ./ghproxyd/${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./ghproxyd/${{ env.OUTPUT_BINARY }}
|
||||
cp LICENSE ./ghproxyd/
|
||||
tar -czf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz -C ghproxyd .
|
||||
ls
|
||||
- name: 上传Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.OUTPUT_BINARY }}
|
||||
name: ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
path: |
|
||||
./${{ env.OUTPUT_BINARY }}*
|
||||
- name: 上传至Release
|
||||
@@ -57,11 +88,12 @@ jobs:
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ env.VERSION }}
|
||||
artifacts: ./${{ env.OUTPUT_BINARY }}*
|
||||
artifacts: ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ env.VERSION }}
|
||||
allowUpdates: true
|
||||
prerelease: true
|
||||
body: ${{ env.VERSION }}
|
||||
env:
|
||||
export PATH: $PATH:/usr/local/go/bin
|
||||
|
||||
@@ -76,6 +108,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: dev
|
||||
- name: Load VERSION
|
||||
run: |
|
||||
if [ -f DEV-VERSION ]; then
|
||||
@@ -104,4 +138,4 @@ jobs:
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE_NAME }}:${{ env.VERSION }}
|
||||
${{ env.IMAGE_NAME }}:dev
|
||||
${{ env.IMAGE_NAME }}:dev
|
||||
83
.github/workflows/build.yml
vendored
83
.github/workflows/build.yml
vendored
@@ -9,60 +9,89 @@ on:
|
||||
- 'VERSION'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
prepare:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [linux]
|
||||
goarch: [amd64, arm64]
|
||||
env:
|
||||
OUTPUT_BINARY: ghproxy
|
||||
GO_VERSION: 1.23.2
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Load VERSION
|
||||
- name: 加载版本号
|
||||
run: |
|
||||
if [ -f VERSION ]; then
|
||||
echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "VERSION file not found!" && exit 1
|
||||
fi
|
||||
- name: Set up Go
|
||||
- name: 输出版本号
|
||||
run: |
|
||||
echo "Version: ${{ env.VERSION }}"
|
||||
- name: 预先创建release
|
||||
id: create_release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ env.VERSION }}
|
||||
artifacts: ./VERSION
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ env.VERSION }}
|
||||
allowUpdates: true
|
||||
body: ${{ env.VERSION }}
|
||||
env:
|
||||
export PATH: $PATH:/usr/local/go/bin
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare # 确保这个作业在 prepare 作业完成后运行
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [linux, darwin, freebsd]
|
||||
goarch: [amd64, arm64]
|
||||
env:
|
||||
OUTPUT_BINARY: ghproxy
|
||||
GO_VERSION: 1.23.6
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: 加载版本号
|
||||
run: |
|
||||
if [ -f VERSION ]; then
|
||||
echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV
|
||||
else
|
||||
echo "VERSION file not found!" && exit 1
|
||||
fi
|
||||
- name: 安装 Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: Install UPX
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y upx
|
||||
- name: Build
|
||||
- name: 编译
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
run: |
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go
|
||||
upx -9 ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
- name: Package
|
||||
CGO_ENABLED=0 go build -ldflags "-s -w -X main.version=${{ env.VERSION }}" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go
|
||||
- name: 打包
|
||||
run: |
|
||||
tar -czvf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
- name: Upload to GitHub Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
mkdir ghproxyd
|
||||
cp ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./ghproxyd/
|
||||
mv ./ghproxyd/${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./ghproxyd/${{ env.OUTPUT_BINARY }}
|
||||
cp LICENSE ./ghproxyd/
|
||||
tar -czf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz -C ghproxyd .
|
||||
- name: 上传Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.OUTPUT_BINARY }}
|
||||
name: ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}
|
||||
path: |
|
||||
./${{ env.OUTPUT_BINARY }}*
|
||||
./${{ env.OUTPUT_BINARY }}*
|
||||
- name: 上传至Release
|
||||
id: create_release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ env.VERSION }}
|
||||
artifacts: ./${{ env.OUTPUT_BINARY }}*
|
||||
artifacts: ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ env.VERSION }}
|
||||
allowUpdates: true
|
||||
body: ${{ env.VERSION }}
|
||||
env:
|
||||
export PATH: $PATH:/usr/local/go/bin
|
||||
export PATH: $PATH:/usr/local/go/bin
|
||||
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build # 确保这个作业在 build 作业完成后运行
|
||||
@@ -101,4 +130,4 @@ jobs:
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.IMAGE_NAME }}:${{ env.VERSION }}
|
||||
${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.IMAGE_NAME }}:latest
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
demo
|
||||
demo.toml
|
||||
*.log
|
||||
*.bak
|
||||
564
CHANGELOG.md
564
CHANGELOG.md
@@ -1,5 +1,569 @@
|
||||
# 更新日志
|
||||
|
||||
2.1.0
|
||||
---
|
||||
- RELEASE: v2.1.0正式版发布;
|
||||
- CHANGE: 加入`FreeBSD`与`Darwin`系统支持
|
||||
- CHANGE: 更新安全政策, v1和24w版本序列生命周期正式结束
|
||||
- ADD: 加入`timing`中间件记录响应时间
|
||||
- ADD: 加入`loggin`中间件包装日志输出
|
||||
- CHANGE: 更新logger版本至v1.3.0
|
||||
- CHANGE: 改进日志相关
|
||||
- ADD: 加入日志等级配置项
|
||||
|
||||
25w12d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.1.0的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 处理类型断言相关问题
|
||||
|
||||
25w12c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.1.0的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 加入`FreeBSD`与`Darwin`系统支持
|
||||
|
||||
25w12b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.8/v2.1.0的预发布版本,请勿在生产环境中使用;
|
||||
- ADD: 加入`timing`中间件记录响应时间
|
||||
- ADD: 加入`loggin`中间件包装日志输出
|
||||
- CHANGE: 更新安全政策, v1和24w版本序列生命周期正式结束
|
||||
|
||||
25w12a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.8/v2.1.0的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 更新logger版本至v1.3.0
|
||||
- CHANGE: 改进日志相关
|
||||
- ADD: 加入日志等级配置项
|
||||
|
||||
2.0.7
|
||||
---
|
||||
- RELEASE: v2.0.7正式版发布;
|
||||
- CHANGE: 更新Go版本至1.23.6
|
||||
- CHANGE: 更新Logger版本至v1.2.0
|
||||
|
||||
25w11a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.7的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 更新Go版本至1.23.6
|
||||
- CHANGE: 更新Logger版本至v1.2.0
|
||||
|
||||
2.0.6
|
||||
---
|
||||
- RELEASE: v2.0.6正式版发布;祝各位新春快乐!
|
||||
- CHANGE: 优化前端的连接转换逻辑
|
||||
- CHANGE: 优化代码内不必要的函数化, 1.4之后, 函数化疑似有点太多了
|
||||
- 优化`HTTP Client`参数
|
||||
- CHANGE: 为api路由组增加no-cache标头
|
||||
|
||||
25w10b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.6的预发布版本,请勿在生产环境中使用;祝各位新春快乐!
|
||||
- CHANGE: 为api路由组增加no-cache标头
|
||||
|
||||
25w10a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.6的预发布版本,请勿在生产环境中使用;祝各位新春快乐!
|
||||
- CHANGE: 改进前端的连接转换逻辑
|
||||
- CHANGE: 优化代码内不必要的函数化, 1.4之后, 函数化疑似有点太多了
|
||||
- 优化`HTTP Client`参数
|
||||
|
||||
2.0.5
|
||||
---
|
||||
- RELEASE: v2.0.5正式版发布;
|
||||
- CHANGE: 优化响应体分块复制实现
|
||||
- ADD: 加入缓存池
|
||||
- CHANGE: 改进缓存实现
|
||||
- CHANGE: 部分杂项改进
|
||||
|
||||
25w09b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.5的预发布版本,请勿在生产环境中使用;
|
||||
- REMOVE: 移除残留配置
|
||||
|
||||
25w09a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.5的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 改进缓存实现
|
||||
- ADD: 加入缓存池
|
||||
|
||||
2.0.4
|
||||
---
|
||||
- RELEASE: v2.0.4正式版发布;
|
||||
- CHANGE: 优化GitReq的`HTTP Client`参数, 使其更符合本项目使用场景
|
||||
- CHANGE: 优化Matches
|
||||
- REMOVE: 移除Caddyfile残留
|
||||
- REMOVE: 由于v2改进后稳定性增强, 故移除健康检测
|
||||
|
||||
25w08b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.4的预发布版本,请勿在生产环境中使用;
|
||||
- REMOVE: 由于v2改进后稳定性增强, 故移除健康检测
|
||||
|
||||
25w08a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.4的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 优化GitReq的`HTTP Client`参数, 使其更符合本项目使用场景
|
||||
- CHANGE: 优化Matches
|
||||
- REMOVE: 移除Caddyfile残留
|
||||
|
||||
2.0.3
|
||||
---
|
||||
- RELEASE: v2.0.3正式版发布;
|
||||
- CHANGE: 优化`HTTP Client`参数, 使其更符合本项目使用场景
|
||||
|
||||
25w07b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.3的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 改进`HTTP Client`参数
|
||||
|
||||
25w07a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.3的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 为`HTTP Client`增加复用, 对性能有所优化
|
||||
- CHANGE: 优化`HTTP Client`参数, 使其更符合本项目使用场景
|
||||
|
||||
2.0.2
|
||||
---
|
||||
- RELEASE: v2.0.2正式版发布; 此版本是v2.0.1改进
|
||||
- CHANGE: 由于用户使用了不符合`RFC 9113`规范的请求头, 导致`ghproxy`无法正常工作, 在此版本为用户的错误行为提供补丁;
|
||||
|
||||
25w06b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是改进验证版本,普通用户请勿使用;
|
||||
- CHANGE: 由于用户使用了不符合`RFC 9113`规范的请求头, 导致`ghproxy`无法正常工作, 在此版本为用户的错误行为提供补丁;
|
||||
|
||||
25w06a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是改进验证版本,普通用户请勿使用;
|
||||
- CHANGE: Remove `Conection: Upgrade` header, which is not currently supported by some web server configurations.
|
||||
|
||||
v2.0.1
|
||||
---
|
||||
- RELEASE: v2.0.1正式版发布; 此版本是v2.0.0的小修复版本, 主要修复了Docker启动脚本存在的一些问题
|
||||
- FIX: 修复Docker启动脚本存在的一些问题
|
||||
|
||||
25w05a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2.0.1的候选版本,请勿在生产环境中使用;
|
||||
- FIX: 修复Docker启动脚本存在的一些问题
|
||||
|
||||
2.0.0
|
||||
---
|
||||
- RELEASE: v2.0.0正式版发布; 此版本圆了几个月前画的饼, 在大文件下载的内存占用方面做出了巨大改进
|
||||
- CHANGE: 优化`proxy`核心模块, 使用Chuncked Buffer传输数据, 减少内存占用
|
||||
- REMOVE: caddy
|
||||
- REMOVE: nocache
|
||||
- CHANGE: 优化前端页面, 增加更多功能(来自1.8.1版本, 原本也是为v2所设计的)
|
||||
|
||||
25w04c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2的候选版本,请勿在生产环境中使用;
|
||||
- CHANGE: 大幅优化`proxy`核心模块, 使用Chuncked Buffer传输数据, 减少内存占用
|
||||
|
||||
v1.8.3
|
||||
---
|
||||
- RELEASE: v1.8.3, 此版本作为v1.8.2的依赖更新版本(在v2发布前, v1仍会进行漏洞修复)
|
||||
- CHANGE: 更新Go版本至`1.23.5`以解决CVE漏洞
|
||||
|
||||
25w04b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版)
|
||||
- REMOVE: caddy
|
||||
|
||||
25w04a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版)
|
||||
- CHANGE: 大幅修改核心组件
|
||||
|
||||
1.8.2
|
||||
---
|
||||
- RELEASE: v1.8.2正式版发布; 这或许会是v1的最后一个版本
|
||||
- FIX: 修复部分日志表述错误
|
||||
- CHANGE: 关闭`gin`框架的`fmt`日志打印, 在高并发场景下提升一定性能(go 打印终端日志性能较差,可能造成性能瓶颈)
|
||||
|
||||
25w03a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.2的候选预发布版本,请勿在生产环境中使用
|
||||
- FIX: 修复部分日志表述错误
|
||||
- CHANGE: 关闭`gin`框架的`fmt`日志打印, 在高并发场景下提升一定性能(go 打印终端日志性能较差,可能造成性能瓶颈)
|
||||
|
||||
1.8.1
|
||||
---
|
||||
- RELEASE: v1.8.1正式版发布; 此版本发布较为仓促, 用于修复caddy2.9.0导致的问题
|
||||
- CHANGE: 更新底包至`v2.9.1`
|
||||
- FIX: 修复caddy2.9.0导致的问题
|
||||
- CHANGE: 对前端进行重构(非最终决定,各位可将其与原先的版本对比, 若有相关建议, 请与开发团队进行交流)
|
||||
|
||||
25w02a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.1的候选预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新底包至`v2.9.1`
|
||||
- CHANGE: 对前端进行重构(非最终决定,各位可将其与原先的版本对比, 若有相关建议, 请与开发团队进行交流)
|
||||
|
||||
v1.8.0
|
||||
---
|
||||
- RELEASE: v1.8.0正式版发布; 这是2025年的第一个正式版本发版,祝各位新年快乐!
|
||||
- CHANGE: 更新底包至`v2.9.0`
|
||||
- CHANGE: 优化`Auth`参数透传至`"Authorization: token {token}"`功能, 增加`dev`参数以便调试
|
||||
- CHANGE: 优化`config.toml`默认配置, 增加`embed.FS`内嵌前端支持, 并优化相关逻辑
|
||||
- CHANGE: 更新前端页面版权声明
|
||||
|
||||
25w01e
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用
|
||||
- FIX: 修复引入token参数透传功能导致的一些问题
|
||||
|
||||
25w01d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 尝试修复部分问题
|
||||
|
||||
25w01c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 改进token参数透传功能
|
||||
|
||||
25w01b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 将底包更新至`v2.9.0`
|
||||
|
||||
25w01a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用; 同时,这也是2025年的第一个pre-release版本,祝各位新年快乐! (同时,请注意版本号的变化)
|
||||
- ADD: 加入`dev`参数, 以便pre-release版本调试(实验性)
|
||||
- ADD: 加入基于`embed.FS`的内嵌前端, config.toml中的`[pages]`配置为false时自动使用内嵌前端
|
||||
- CHANGE: 完善24w29a版本新加入的`Auth`参数透传至`"Authorization: token {token}"`功能,对相关逻辑进行完善
|
||||
- FIX: 修正24w29a版本新加入的`Auth`参数透传至`"Authorization: token {token}"`功能的一些问题
|
||||
|
||||
24w29a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是一个实验性功能测试版本,请勿在生产环境中使用; 同时,这也是2024年的最后一个pre-release版本
|
||||
- ADD: `Auth` token参数透传至`"Authorization: token {token}"`, 为私有仓库拉取提供一定便利性(需要更多测试)
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
v1.7.9
|
||||
---
|
||||
- RELEASE: 安全性及小型修复, 建议用户自行选择是否升级
|
||||
- CHANGE: 将`logger`库作为外部库引入, 使维护性更好, 同时修正了部分日志问题并提升部分性能
|
||||
- CHANGE: 更新相关依赖库, 更新`req`库以解决`net`标准库的`CVE-2021-38561`漏洞
|
||||
- FIX: 修复安装脚本内的错误
|
||||
|
||||
24w28b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.9的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 将`logger`库作为外部库引入, 使维护性更好, 同时修正了部分日志问题并提升部分性能
|
||||
|
||||
24w28a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.9的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新相关依赖库, 更新`req`库以解决`net`标准库的`CVE-2021-38561`漏洞
|
||||
- FIX: 修复安装脚本内的错误
|
||||
|
||||
v1.7.8
|
||||
---
|
||||
- RELEASE: 我们建议您升级到此版本, 以解决一些依赖库的安全漏洞和与caddy相关的内存问题
|
||||
- CHANGE: 更新底包至`v24.12.20`可能解决部分与`caddy`相关的内存问题
|
||||
- CHANGE: 更新相关依赖库,解决`net`标准库的`CVE-2024-45338`
|
||||
- CHANGE: 小幅更新前端页面
|
||||
- FIX: 修复`config.toml`默认配置内的错误
|
||||
- ADD: 新增`api.github.com`反代支持, 强制性要求开启`Header Auth`功能(需要更多测试)
|
||||
|
||||
24w27e
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.8的预发布候选版本(若无问题,此版本将会成为v1.7.8正式版本),请勿在生产环境中使用
|
||||
- CHANGE: 更新底包至`v24.12.20`可能解决部分与`caddy`相关的内存问题
|
||||
|
||||
24w27d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.8的预发布候选版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新相关依赖库,解决`net`标准库的`CVE-2024-45338`
|
||||
- CHANGE: 小幅更新前端页面
|
||||
|
||||
24w27c
|
||||
---
|
||||
- PRE-RELEASE: 此版本做为实验性功能测试版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新docker底包至`v2.9.0-beta.3` , 可能解决部分内存相关问题
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
24w27b
|
||||
---
|
||||
- PRE-RELEASE: 此版本做为实验性功能测试版本,请勿在生产环境中使用
|
||||
- FIX: 修复`config.toml`默认配置内的错误
|
||||
|
||||
24w27a
|
||||
---
|
||||
- PRE-RELEASE: 此版本做为实验性功能测试版本,请勿在生产环境中使用
|
||||
- ADD: 新增`api.github.com`反代支持, 强制性要求开启`Header Auth`功能
|
||||
|
||||
v1.7.7
|
||||
---
|
||||
- CHANGE: 更新相关依赖库
|
||||
- CHANGE: 更新Go版本至1.23.4
|
||||
- CHANGE: 更新release及dev版本底包
|
||||
|
||||
24w26a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.7的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新相关依赖库
|
||||
- CHANGE: 更新Go版本至1.23.4
|
||||
- CHANGE: 更新release及dev版本底包
|
||||
|
||||
v1.7.6
|
||||
---
|
||||
- RELEASE: 版本在v1.7.4及以上的用户,我们建议升级到此版本以解决于v1.7.4版本功能更新所引入的问题
|
||||
- FIX: 进一步修正 H2C相关配置逻辑问题
|
||||
- CHANGE: 对Caddy配置进行实验性修改,优化H2C配置
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
24w25b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.6的预发布版本,请勿在生产环境中使用
|
||||
- 说明: 本版本为24w25a-fix0
|
||||
- FIX: 进一步修正 H2C相关配置逻辑问题
|
||||
|
||||
24w25a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.6的预发布版本,请勿在生产环境中使用
|
||||
- 说明: 本版本为v1.7.6的其中一个候选与开发测试版本,相关改动不一定实装
|
||||
- FIX: 进一步修正 H2C相关配置逻辑问题
|
||||
- CHANGE: 对Caddy配置进行实验性修改,优化H2C配置
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
v1.7.5
|
||||
---
|
||||
- FIX: 修复 v1.7.4 版本 Docker 镜像默认配置导致的 403 问题
|
||||
- ADD: `Rate`模块加入`IP`速率限制,可限制单个IP的请求速率 (需要更多测试)
|
||||
- CHANGE: 处理积攒的依赖库更新
|
||||
|
||||
24w24c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.5的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新依赖
|
||||
|
||||
24w24b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.5的预发布版本,请勿在生产环境中使用
|
||||
- FIX: 修复 Docker 默认配置导致的 403 问题
|
||||
|
||||
24w24a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.5的预发布版本,请勿在生产环境中使用
|
||||
- ADD: `Rate`模块加入`IP`速率限制,可限制单个IP的请求速率 (需要更多测试)
|
||||
- CHANGE: 处理积攒的依赖库更新,更新如下依赖库:
|
||||
- **github.com/gabriel-vasile/mimetype**: 从 v1.4.6 升级到 v1.4.7
|
||||
- **github.com/go-playground/validator/v10**: 从 v10.22.1 升级到 v10.23.0
|
||||
- **github.com/klauspost/cpuid/v2**: 从 v2.2.8 升级到 v2.2.9
|
||||
- **github.com/onsi/ginkgo/v2**: 从 v2.21.0 升级到 v2.22.0
|
||||
- **golang.org/x/arch**: 从 v0.11.0 升级到 v0.12.0
|
||||
- **golang.org/x/crypto**: 从 v0.28.0 升级到 v0.29.0
|
||||
- **golang.org/x/exp**: 从 v0.0.0-20241009180824-f66d83c29e7c 升级到 v0.0.0-20241108190413-2d47ceb2692f
|
||||
- **golang.org/x/mod**: 从 v0.21.0 升级到 v0.22.0
|
||||
- **golang.org/x/net**: 从 v0.30.0 升级到 v0.31.0
|
||||
- **golang.org/x/sync**: 从 v0.8.0 升级到 v0.9.0
|
||||
- **golang.org/x/sys**: 从 v0.26.0 升级到 v0.27.0
|
||||
- **golang.org/x/text**: 从 v0.19.0 升级到 v0.20.0
|
||||
- **golang.org/x/tools**: 从 v0.26.0 升级到 v0.27.0
|
||||
- **google.golang.org/protobuf**: 从 v1.35.1 升级到 v1.35.2
|
||||
|
||||
v1.7.4
|
||||
---
|
||||
- CHANGE: 对二进制文件部署脚本进行优化
|
||||
- CHANGE&ADD: 新增H2C相关配置
|
||||
- ADD: `Auth`模块加入`Header`鉴权,使用`GH-Auth`的值进行鉴权
|
||||
|
||||
24w23a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.4的预发布版本,请勿在生产环境中使用
|
||||
- ADD: `Auth`模块加入`Header`鉴权,使用`GH-Auth`的值进行鉴权
|
||||
- CHANGE: 对二进制文件部署脚本进行优化
|
||||
- CHANGE&ADD: 新增H2C相关配置
|
||||
|
||||
v1.7.3
|
||||
---
|
||||
- CHANGE: Bump golang.org/x/time from 0.7.0 to 0.8.0
|
||||
- FIX: 修复故障熔断的相关问题
|
||||
|
||||
v1.7.2
|
||||
---
|
||||
- CHANGE: 为`nocache`版本加入测试性的故障熔断机制
|
||||
|
||||
v1.7.1
|
||||
---
|
||||
- CHANGE: 更新Go版本至1.23.3
|
||||
- CHANGE: 更新相关依赖库
|
||||
- ADD: 对`Proxy`模块进行优化,增加使用`HEAD`方式预获取`Content-Length`头
|
||||
- CHANGE: 将`release`与`dev`版本的底包切换至`wjqserver/caddy:2.9.0-rc4-alpine`,将`nocache`版本的底包切换至`alpine:latest`
|
||||
- CHANGE: 对`nocache`版本的`config.toml`与`init.sh`进行适配性修改
|
||||
- CHANGE: 加入测试性的故障熔断机制(Failure Circuit Breaker) (nocache版本暂不支持)
|
||||
|
||||
24w22b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.1的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新Go版本至1.23.3
|
||||
- CHANGE: 更新相关依赖库
|
||||
- ADD: 对`Proxy`模块进行优化,增加使用`HEAD`方式预获取`Content-Length`头
|
||||
- CHANGE: 将`release`与`dev`版本的底包切换至`wjqserver/caddy:2.9.0-rc4-alpine`,将`nocache`版本的底包切换至`alpine:latest`
|
||||
- CHANGE: 对`nocache`版本的`config.toml`与`init.sh`进行适配性修改
|
||||
|
||||
24w22a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.1的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新底包
|
||||
- CHANGE: 加入测试性的故障熔断机制(Failure Circuit Breaker)
|
||||
|
||||
v1.7.0
|
||||
---
|
||||
- ADD: 加入`rate`模块,实现内置速率限制
|
||||
- CHANGE: 优化`blacklist`与`whitelist`模块的匹配算法,提升性能;由原先的完整匹配改为切片匹配,提升匹配效率
|
||||
- ADD: 加入`version`相关表示与API接口
|
||||
- ADD: 加入`rate`相关API接口
|
||||
- CHANGE: 优化前端界面,优化部分样式
|
||||
- CHANGE: 更新相关依赖库
|
||||
- CHANGE: 对编译打包进行改进,此后不再提供独立可执行文件,请改为拉取`tar.gz`压缩包
|
||||
|
||||
24w21d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用
|
||||
- ADD: 新增`ratePerMinute` API可供查询
|
||||
- ADD: 前端新增 version 标识
|
||||
- ADD: 前端新增 `重定向` 按钮,用于重定向到代理后的链接
|
||||
- CHANGE: 优化输出代码块,使样式更加美观
|
||||
- CHANGE: 更新相关依赖库
|
||||
- CHANGE: 对黑名单模块进行实验性功能优化,提升性能(改进匹配算法,在切片后优先匹配user,减少无效匹配)
|
||||
|
||||
24w21c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 对编译打包进行改进,此后不再提供独立可执行文件,请改为拉取`tar.gz`压缩包
|
||||
- CHANGE: 由于上述原因,对Docker打包进行相应改进
|
||||
|
||||
24w21b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用
|
||||
- ADD: 加入版本号标识与对应API接口
|
||||
- ADD: 加入速率限制API接口
|
||||
- CHANGE: 修改打包部分
|
||||
|
||||
24w21a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.7.0的预发布版本,请勿在生产环境中使用
|
||||
- ADD: 尝试加入程序内置速率限制
|
||||
- CHANGE: 更新相关依赖库
|
||||
- CHANGE: 更换Dev版本底包,于release版本保持一致
|
||||
|
||||
v1.6.2
|
||||
---
|
||||
- CHANGE: 优化前端界面,优化部分样式
|
||||
- ADD: 前端加入黑夜模式
|
||||
- CHANGE: 优化移动端适配
|
||||
- CHANGE: 优化一键部署脚本,使其更加易用,并增加更多的功能(已于早些时候hotfix)
|
||||
- CHANGE: 优化部分代码结构,提升性能
|
||||
- CHANGE: 优化日志记录,对各个部分的日志记录进行统一格式,并对部分重复日志进行合并
|
||||
|
||||
24w20b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.2的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 优化前端界面,优化部分样式
|
||||
- ADD: 前端加入黑夜模式
|
||||
- CHANGE: 优化移动端适配
|
||||
|
||||
24w20a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.2的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 大幅修改日志记录,对各个部分的日志记录进行统一格式,并对部分重复日志进行合并
|
||||
- CHANGE: 大幅优化一键部署脚本,使其更加易用,并增加更多的功能(已于早些时候hotfix)
|
||||
- CHANGE: 优化部分代码结构,提升性能
|
||||
|
||||
v1.6.1
|
||||
---
|
||||
- CHANGE: 根据社区建议,将`sizeLimit`由过去的以`byte`为单位,改为以`MB`为单位,以便于直观理解
|
||||
- ADD: 新增`nocache`版本,供由用户自行优化缓存策略
|
||||
- CHANGE: 优化`Proxy`核心模块内部结构,提升性能
|
||||
- REMOVE: 移除`Proxy`模块内部分无用`logInfo`
|
||||
- FIX & ADD: 修复前端对gist的匹配问题,添加对`gist.githubusercontent.com`的前端转换支持
|
||||
- CHANGE: 改变部分前端匹配逻辑
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
24w19d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.1的预发布版本,请勿在生产环境中使用
|
||||
- ADD: 新增nocache版本,供由用户自行优化缓存策略
|
||||
- CHANGE: 优化`Proxy`核心模块内部结构,提升性能
|
||||
- REMOVE: 移除`Proxy`模块内部分无用`logInfo`
|
||||
|
||||
24w19c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.1的预发布版本,请勿在生产环境中使用
|
||||
- FIX & ADD: 修复前端对gist的匹配问题,添加对`gist.githubusercontent.com`的前端转换支持
|
||||
- CHANGE: 改变部分前端匹配逻辑
|
||||
- CHANGE: 更新相关依赖库
|
||||
|
||||
24w19b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.1的预发布版本,请勿在生产环境中使用
|
||||
- FIX: 修复`sizeLimit`单位更改导致API返回值错误的问题
|
||||
- FIX: 修正Gist匹配
|
||||
|
||||
24w19a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.1的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 根据社区建议,将`sizeLimit`由过去的以`byte`为单位,改为以`MB`为单位,以便于直观理解
|
||||
- CHANGE: 更新相关依赖
|
||||
- CHANGE: 对`Proxy`模块的核心函数进行模块化,为后续修改和扩展提供空间
|
||||
|
||||
v1.6.0
|
||||
---
|
||||
- CHANGE: 优化代码结构,提升性能
|
||||
- CHANGE: 引入H2C支持,支持无加密HTTP/2请求,一定程度上提升传输性能
|
||||
- ADD: 在核心程序内加入静态页面支持,支持不通过caddy等web server提供前端页面
|
||||
- CHANGE: 优化日志记录,带来更多的可观测性
|
||||
- CHANGE: 改进前端界面,优化用户体验; 对原有Alert提示进行优化,改为ShowToast提示
|
||||
- CHANGE: 规范化部分函数命名,提升可读性; 同时对config.toml内的参数命名进行规范化(部分参数名称已过时,请注意更新)
|
||||
- CHANGE: 修改日志检查周期,降低检查频率,避免不必要的资源浪费
|
||||
- ADD: 增加CORS状态API
|
||||
|
||||
24w18f
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.0的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 修正前端页面的部分样式问题
|
||||
- FIX: 修正部分问题
|
||||
|
||||
24w18e
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 引入H2C协议支持,支持无加密HTTP/2请求
|
||||
- ADD: 尝试在核心程序内加入静态页面支持
|
||||
- CHANGE: 优化日志记录
|
||||
- CHANGE: 去除部分无用/重复配置
|
||||
- CHANGE: 规范化部分函数命名
|
||||
|
||||
24w18d
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 更新相关依赖库
|
||||
- ADD: 增加CORS状态API
|
||||
- CHANGE: 优化部分函数执行顺序
|
||||
- CHANGE: 优化前端界面
|
||||
|
||||
24w18c
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 修正配置命名,改为驼峰式命名
|
||||
- CHANGE: 修正函数命名
|
||||
|
||||
24w18b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 经团队考量,移除 Docker 代理功能,若造成了不便敬请谅解
|
||||
- CHANGE: 修改日志检查周期
|
||||
|
||||
24w18a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 改进Docker 代理
|
||||
- CHANGE: 改进前端页面的copy提示,弃用alert提示
|
||||
|
||||
v1.5.2
|
||||
---
|
||||
- FIX: 修正flag传入问题
|
||||
|
||||
@@ -1 +1 @@
|
||||
24w17b
|
||||
25w12d
|
||||
71
README.md
71
README.md
@@ -1,34 +1,37 @@
|
||||
# GhProxy
|
||||
# GHProxy
|
||||
|
||||

|
||||

|
||||
[](https://goreportcard.com/report/github.com/WJQSERVER-STUDIO/ghproxy)
|
||||
|
||||
使用Go实现的GHProxy,用于加速部分地区Github仓库的拉取,支持速率限制,用户鉴权,支持Docker部署
|
||||
|
||||
[DEMO](https://ghproxy.1888866.xyz)
|
||||
|
||||
[TG讨论群组](https://t.me/ghproxy_go)
|
||||
|
||||
[版本更新介绍](https://blog.wjqserver.com/categories/my-program/)
|
||||
|
||||
## 项目说明
|
||||
|
||||
### 项目特点
|
||||
|
||||
- 基于Go语言实现,使用[Gin框架](https://github.com/gin-gonic/gin)与[req库](https://github.com/imroc/req)]
|
||||
- 基于Go语言实现,使用[Gin框架](https://github.com/gin-gonic/gin)
|
||||
- 支持Git clone,raw,realeases等文件拉取
|
||||
- 支持Docker部署
|
||||
- 支持速率限制
|
||||
- 支持用户鉴权
|
||||
- 支持自定义黑名单/白名单
|
||||
- 符合[RFC 7234](https://httpwg.org/specs/rfc7234.html)的HTTP Cache
|
||||
- 使用Caddy作为Web Server
|
||||
- 基于[WJQSERVER-STUDIO/golang-temp](https://github.com/WJQSERVER-STUDIO/golang-temp)模板构建,具有标准化的日志记录与构建流程
|
||||
|
||||
### 项目开发过程
|
||||
|
||||
**本项目是[WJQSERVER-STUDIO/ghproxy-go](https://github.com/WJQSERVER-STUDIO/ghproxy-go)的重构版本,实现了原项目原定功能的同时,进一步优化了性能**
|
||||
本项目源于[WJQSERVER-STUDIO/ghproxy-go](https://github.com/WJQSERVER-STUDIO/ghproxy-go)与[WJQSERVER/ghproxy-go-0RTT](https://github.com/WJQSERVER/ghproxy-go-0RTT)两个项目,前者带来了实现框架与资源,后者带来了解决Git clone问题的办法,使得本项目从net/http标准库切换至Gin框架,已解决此困扰已久的问题,在此基础上,本项目进一步优化了性能,并添加了用户鉴权功能,使得部署更加安全可靠。
|
||||
关于此项目的详细开发过程,请参看Commit记录与[CHANGELOG.md](https://github.com/WJQSERVER-STUDIO/ghproxy/blob/main/CHANGELOG.md)
|
||||
|
||||
- V2.0.0 对`proxy`核心模块进行了重构,大幅优化内存占用
|
||||
- V1.0.0 迁移至本仓库,并再次重构内容实现
|
||||
- v0.2.0 重构项目实现,Git clone的实现完全自主化
|
||||
- v0.2.0 重构项目实现
|
||||
|
||||
### LICENSE
|
||||
|
||||
@@ -39,8 +42,10 @@
|
||||
## 使用示例
|
||||
|
||||
```
|
||||
# 下载文件
|
||||
https://ghproxy.1888866.xyz/raw.githubusercontent.com/WJQSERVER-STUDIO/tools-stable/main/tools-stable-ghproxy.sh
|
||||
|
||||
# 克隆仓库
|
||||
git clone https://ghproxy.1888866.xyz/github.com/WJQSERVER-STUDIO/ghproxy.git
|
||||
```
|
||||
|
||||
@@ -51,10 +56,10 @@ git clone https://ghproxy.1888866.xyz/github.com/WJQSERVER-STUDIO/ghproxy.git
|
||||
- Docker-cli
|
||||
|
||||
```
|
||||
docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/caddy:/data/caddy/log -v ./ghproxy/config:/data/ghproxy/config --restart always wjqserver/ghproxy
|
||||
docker run -p 7210:8080 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/caddy:/data/caddy/log -v ./ghproxy/config:/data/ghproxy/config --restart always wjqserver/ghproxy
|
||||
```
|
||||
|
||||
- Docker-Compose
|
||||
- Docker-Compose (建议使用)
|
||||
|
||||
参看[docker-compose.yml](https://github.com/WJQSERVER-STUDIO/ghproxy/blob/main/docker/compose/docker-compose.yml)
|
||||
|
||||
@@ -75,29 +80,41 @@ wget -O install.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/ma
|
||||
|
||||
```toml
|
||||
[server]
|
||||
host = "127.0.0.1" # 监听地址(小白请勿修改)
|
||||
port = 8080 #监听端口(小白请勿修改)
|
||||
sizelimit = 131072000 # 125MB
|
||||
host = "0.0.0.0" # 监听地址
|
||||
port = 8080 # 监听端口
|
||||
sizeLimit = 125 # 125MB
|
||||
enableH2C = "on" # 是否开启H2C传输(latest和dev版本请开启) on/off
|
||||
|
||||
[pages]
|
||||
enabled = false # 是否开启内置静态页面(Docker版本请关闭此项)
|
||||
staticPath = "/data/www" # 静态页面文件路径
|
||||
|
||||
[log]
|
||||
logfilepath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径(小白请勿修改)
|
||||
maxlogsize = 5 # MB
|
||||
logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径
|
||||
maxLogSize = 5 # MB 日志文件最大大小
|
||||
level = "info" # 日志级别 dump, debug, info, warn, error, none
|
||||
|
||||
[cors]
|
||||
enabled = true # 是否开启CORS
|
||||
enabled = true # 是否开启跨域
|
||||
|
||||
[auth]
|
||||
authtoken = "test" # 鉴权Token
|
||||
enabled = false # 是否开启鉴权
|
||||
authMethod = "parameters" # 鉴权方式,支持parameters,header
|
||||
authToken = "token" # 用户鉴权Token
|
||||
enabled = false # 是否开启用户鉴权
|
||||
|
||||
[blacklist]
|
||||
blacklistfile = "/data/ghproxy/config/blacklist.json" # 黑名单文件路径
|
||||
blacklistFile = "/data/ghproxy/config/blacklist.json" # 黑名单文件路径
|
||||
enabled = false # 是否开启黑名单
|
||||
|
||||
[whitelist]
|
||||
enabled = false # 是否开启白名单
|
||||
whitelistfile = "/data/ghproxy/config/whitelist.json" # 白名单文件路径
|
||||
whitelistFile = "/data/ghproxy/config/whitelist.json" # 白名单文件路径
|
||||
|
||||
[rateLimit]
|
||||
enabled = false # 是否开启速率限制
|
||||
rateMethod = "total" # "ip" or "total" 速率限制方式
|
||||
ratePerMinute = 180 # 每分钟限制请求数量
|
||||
burst = 5 # 突发请求数量
|
||||
```
|
||||
|
||||
### 黑名单配置
|
||||
@@ -134,10 +151,6 @@ whitelistfile = "/data/ghproxy/config/whitelist.json" # 白名单文件路径
|
||||
example.com {
|
||||
reverse_proxy {
|
||||
to 127.0.0.1:7210
|
||||
header_up X-Real-IP {remote_host}
|
||||
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-Proto {http.request.header.CF-Visitor}
|
||||
}
|
||||
encode zstd gzip
|
||||
}
|
||||
@@ -145,15 +158,5 @@ example.com {
|
||||
|
||||
### 前端页面
|
||||
|
||||

|
||||
|
||||
## TODO & DEV
|
||||
|
||||
### TODO
|
||||
- [x] 用户鉴权
|
||||
- [x] 仓库黑名单
|
||||
- [x] 仓库白名单
|
||||
|
||||
### DEV
|
||||
|
||||
- [x] Docker Pull 代理
|
||||

|
||||

|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
| 版本 | 是否支持 |
|
||||
| --- | --- |
|
||||
| v1.x.x | :white_check_mark: |
|
||||
| **w**a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 |
|
||||
| v2.x.x | :white_check_mark: 当前最新版本序列, 受支持 |
|
||||
| v1.x.x | :x: 这些版本已结束生命周期,不再受支持 |
|
||||
| 25w*a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 |
|
||||
| 24w*a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 生命周期已完全结束 |
|
||||
| v0.x.x | :x: 这些版本不再受支持 |
|
||||
|
||||
### 用户须知
|
||||
@@ -16,6 +18,8 @@
|
||||
|
||||
使用本项目,请遵循 **[WSL (WJQSERVER-STUDIO LICENSE)](https://wjqserver-studio.github.io/LICENSE/LICENSE.html)** 协议。
|
||||
|
||||
本项目所有文件均受到 WSL (WJQSERVER-STUDIO LICENSE) 协议保护,任何人不得在任何情况下以非 WSL (WJQSERVER-STUDIO LICENSE) 协议内规定的方式使用,复制,修改,编译,发布,分发,再许可,或者出售本项目的任何部分。
|
||||
|
||||
## 报告漏洞
|
||||
|
||||
如果您发现本项目存在安全漏洞,请通过发送ISSUES或尝试联系项目维护者来报告。请在您的报告中包含以下信息:
|
||||
|
||||
77
api/api.go
77
api/api.go
@@ -3,8 +3,8 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -13,17 +13,27 @@ var (
|
||||
cfg *config.Config
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
LogWarning = logger.LogWarning
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
|
||||
// 设置路由
|
||||
apiRouter := router.Group("api")
|
||||
func NoCacheMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 设置禁止缓存的响应头
|
||||
c.Header("Cache-Control", "no-store, no-cache, must-revalidate")
|
||||
c.Header("Pragma", "no-cache")
|
||||
c.Header("Expires", "0")
|
||||
c.Next() // 继续处理请求
|
||||
}
|
||||
}
|
||||
|
||||
func InitHandleRouter(cfg *config.Config, router *gin.Engine, version string) {
|
||||
apiRouter := router.Group("api", NoCacheMiddleware())
|
||||
{
|
||||
apiRouter.GET("/size_limit", func(c *gin.Context) {
|
||||
SizeLimitHandler(cfg, c)
|
||||
@@ -34,17 +44,28 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
|
||||
apiRouter.GET("/blacklist/status", func(c *gin.Context) {
|
||||
BlackListStatusHandler(c, cfg)
|
||||
})
|
||||
apiRouter.GET("/cors/status", func(c *gin.Context) {
|
||||
CorsStatusHandler(c, cfg)
|
||||
})
|
||||
apiRouter.GET("/healthcheck", func(c *gin.Context) {
|
||||
HealthcheckHandler(c)
|
||||
})
|
||||
apiRouter.GET("/version", func(c *gin.Context) {
|
||||
VersionHandler(c, version)
|
||||
})
|
||||
apiRouter.GET("/rate_limit/status", func(c *gin.Context) {
|
||||
RateLimitStatusHandler(c, cfg)
|
||||
})
|
||||
apiRouter.GET("/rate_limit/limit", func(c *gin.Context) {
|
||||
RateLimitLimitHandler(c, cfg)
|
||||
})
|
||||
}
|
||||
logInfo("API router Init success")
|
||||
}
|
||||
|
||||
func SizeLimitHandler(cfg *config.Config, c *gin.Context) {
|
||||
// 转换为MB
|
||||
sizeLimit := cfg.Server.SizeLimit / 1024 / 1024
|
||||
// 设置响应头
|
||||
sizeLimit := cfg.Server.SizeLimit
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"MaxResponseBodySize": sizeLimit,
|
||||
@@ -52,7 +73,7 @@ func SizeLimitHandler(cfg *config.Config, c *gin.Context) {
|
||||
}
|
||||
|
||||
func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
// 设置响应头
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Whitelist": cfg.Whitelist.Enabled,
|
||||
@@ -60,17 +81,49 @@ func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
}
|
||||
|
||||
func BlackListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
// 设置响应头
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Blacklist": cfg.Blacklist.Enabled,
|
||||
})
|
||||
}
|
||||
|
||||
func CorsStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Cors": cfg.CORS.Enabled,
|
||||
})
|
||||
}
|
||||
|
||||
func HealthcheckHandler(c *gin.Context) {
|
||||
// 设置响应头
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Status": "OK",
|
||||
})
|
||||
}
|
||||
|
||||
func VersionHandler(c *gin.Context, version string) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Version": version,
|
||||
})
|
||||
}
|
||||
|
||||
func RateLimitStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"RateLimit": cfg.RateLimit.Enabled,
|
||||
})
|
||||
}
|
||||
|
||||
func RateLimitLimitHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"RatePerMinute": cfg.RateLimit.RatePerMinute,
|
||||
})
|
||||
}
|
||||
|
||||
29
auth/auth-header.go
Normal file
29
auth/auth-header.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AuthHeaderHandler(c *gin.Context, cfg *config.Config) (isValid bool, err string) {
|
||||
if !cfg.Auth.Enabled {
|
||||
return true, ""
|
||||
}
|
||||
// 获取"GH-Auth"的值
|
||||
authToken := c.GetHeader("GH-Auth")
|
||||
logDebug("%s %s %s %s %s AUTH_TOKEN: %s", c.Request.Method, c.Request.Host, c.Request.URL.Path, c.Request.Proto, c.Request.RemoteAddr, authToken)
|
||||
if authToken == "" {
|
||||
err := "Auth Header == nil"
|
||||
return false, err
|
||||
}
|
||||
|
||||
isValid = authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
err := fmt.Sprintf("Auth token incorrect: %s", authToken)
|
||||
return false, err
|
||||
}
|
||||
|
||||
return isValid, ""
|
||||
}
|
||||
30
auth/auth-parameters.go
Normal file
30
auth/auth-parameters.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AuthParametersHandler(c *gin.Context, cfg *config.Config) (isValid bool, err string) {
|
||||
if !cfg.Auth.Enabled {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
authToken := c.Query("auth_token")
|
||||
logDebug("%s %s %s %s %s AUTH_TOKEN: %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto, authToken)
|
||||
|
||||
if authToken == "" {
|
||||
err := "Auth token == nil"
|
||||
return false, err
|
||||
}
|
||||
|
||||
isValid = authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
err := fmt.Sprintf("Auth token incorrect: %s", authToken)
|
||||
return false, err
|
||||
}
|
||||
|
||||
return isValid, ""
|
||||
}
|
||||
45
auth/auth.go
45
auth/auth.go
@@ -2,20 +2,20 @@ package auth
|
||||
|
||||
import (
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
LogWarning = logger.LogWarning
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
// Auth Init
|
||||
func Init(cfg *config.Config) {
|
||||
if cfg.Blacklist.Enabled {
|
||||
LoadBlacklist(cfg)
|
||||
@@ -23,30 +23,21 @@ func Init(cfg *config.Config) {
|
||||
if cfg.Whitelist.Enabled {
|
||||
LoadWhitelist(cfg)
|
||||
}
|
||||
logInfo("Auth Init")
|
||||
logDebug("Auth Init")
|
||||
}
|
||||
|
||||
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
||||
// 如果身份验证未启用,直接返回 true
|
||||
if !cfg.Auth.Enabled {
|
||||
return true
|
||||
func AuthHandler(c *gin.Context, cfg *config.Config) (isValid bool, err string) {
|
||||
if cfg.Auth.AuthMethod == "parameters" {
|
||||
isValid, err = AuthParametersHandler(c, cfg)
|
||||
return isValid, err
|
||||
} else if cfg.Auth.AuthMethod == "header" {
|
||||
isValid, err = AuthHeaderHandler(c, cfg)
|
||||
return isValid, err
|
||||
} else if cfg.Auth.AuthMethod == "" {
|
||||
logError("Auth method not set")
|
||||
return true, ""
|
||||
} else {
|
||||
logError("Auth method not supported")
|
||||
return false, "Auth method not supported"
|
||||
}
|
||||
|
||||
// 获取 auth_token 参数
|
||||
authToken := c.Query("auth_token")
|
||||
logInfo("auth_token received: %s", authToken)
|
||||
|
||||
// 验证 token
|
||||
if authToken == "" {
|
||||
LogWarning("auth FAILED: no auth_token provided")
|
||||
return false
|
||||
}
|
||||
|
||||
isValid := authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
LogWarning("auth FAILED: invalid auth_token: %s", authToken)
|
||||
}
|
||||
|
||||
logInfo("auth SUCCESS: %t", isValid)
|
||||
return isValid
|
||||
}
|
||||
|
||||
@@ -32,9 +32,8 @@ func LoadBlacklist(cfg *config.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// fullrepo: "owner/repo" or "owner/*"
|
||||
func CheckBlacklist(fullrepo string) bool {
|
||||
return forRangeCheckBlacklist(blacklist.Blacklist, fullrepo)
|
||||
func CheckBlacklist(repouser string, user string, repo string) bool {
|
||||
return forRangeCheckBlacklist(blacklist.Blacklist, repouser, user)
|
||||
}
|
||||
|
||||
func sliceRepoName_Blacklist(fullrepo string) (string, string) {
|
||||
@@ -45,11 +44,16 @@ func sliceRepoName_Blacklist(fullrepo string) (string, string) {
|
||||
return s[0], s[1]
|
||||
}
|
||||
|
||||
func forRangeCheckBlacklist(blist []string, fullrepo string) bool {
|
||||
repoUser, _ := sliceRepoName_Blacklist(fullrepo)
|
||||
func forRangeCheckBlacklist(blist []string, fullrepo string, user string) bool {
|
||||
for _, blocked := range blist {
|
||||
if blocked == fullrepo || (strings.HasSuffix(blocked, "/*") && strings.HasPrefix(repoUser, blocked[:len(blocked)-2])) {
|
||||
return true
|
||||
users, _ := sliceRepoName_Blacklist(blocked)
|
||||
if user == users {
|
||||
if strings.HasSuffix(blocked, "/*") {
|
||||
return true
|
||||
}
|
||||
if fullrepo == blocked {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -31,8 +31,8 @@ func LoadWhitelist(cfg *config.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckWhitelist(fullrepo string) bool {
|
||||
return forRangeCheckWhitelist(whitelist.Whitelist, fullrepo)
|
||||
func CheckWhitelist(fullrepo string, user string, repo string) bool {
|
||||
return forRangeCheckWhitelist(whitelist.Whitelist, fullrepo, user)
|
||||
}
|
||||
|
||||
func sliceRepoName_Whitelist(fullrepo string) (string, string) {
|
||||
@@ -43,11 +43,16 @@ func sliceRepoName_Whitelist(fullrepo string) (string, string) {
|
||||
return s[0], s[1]
|
||||
}
|
||||
|
||||
func forRangeCheckWhitelist(wlist []string, fullrepo string) bool {
|
||||
repoUser, _ := sliceRepoName_Whitelist(fullrepo)
|
||||
for _, blocked := range wlist {
|
||||
if blocked == fullrepo || (strings.HasSuffix(blocked, "/*") && strings.HasPrefix(repoUser, blocked[:len(blocked)-2])) {
|
||||
return true
|
||||
func forRangeCheckWhitelist(wlist []string, fullrepo string, user string) bool {
|
||||
for _, passd := range wlist {
|
||||
users, _ := sliceRepoName_Whitelist(passd)
|
||||
if users == user {
|
||||
if strings.HasSuffix(passd, "/*") {
|
||||
return true
|
||||
}
|
||||
if fullrepo == passd {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
{
|
||||
debug
|
||||
http_port 80
|
||||
https_port 443
|
||||
order cache before rewrite
|
||||
cache {
|
||||
cache_name GhProxyCache
|
||||
}
|
||||
log {
|
||||
level INFO
|
||||
output file /data/caddy/log/caddy.log {
|
||||
roll_size 5MB
|
||||
roll_keep 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(log) {
|
||||
log {
|
||||
format transform `{request>headers>X-Forwarded-For>[0]:request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` {
|
||||
time_format "02/Jan/2006:15:04:05 -0700"
|
||||
}
|
||||
output file /data/caddy/log/{args[0]}/access.log {
|
||||
roll_size 5MB
|
||||
roll_keep 10
|
||||
roll_keep_for 24h
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(error_page) {
|
||||
handle_errors {
|
||||
rewrite * /{err.status_code}.html
|
||||
root * /data/caddy/pages/errors
|
||||
file_server
|
||||
}
|
||||
}
|
||||
|
||||
(encode) {
|
||||
encode {
|
||||
zstd best
|
||||
br 5 v2
|
||||
gzip 5
|
||||
minimum_length 512
|
||||
}
|
||||
}
|
||||
|
||||
(cache) {
|
||||
cache {
|
||||
allowed_http_verbs GET
|
||||
stale {args[0]}
|
||||
ttl {args[1]}
|
||||
}
|
||||
}
|
||||
|
||||
(header_realip) {
|
||||
header_up X-Real-IP {remote_host}
|
||||
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-Proto {http.request.header.CF-Visitor}
|
||||
}
|
||||
|
||||
(rate_limit) {
|
||||
route /* {
|
||||
rate_limit {remote.ip} {args[0]}r/m 10000 429
|
||||
}
|
||||
}
|
||||
|
||||
:80 {
|
||||
reverse_proxy {
|
||||
to 127.0.0.1:8080
|
||||
import header_realip
|
||||
}
|
||||
import log ghproxy
|
||||
import cache 0s 300s
|
||||
import error_page
|
||||
import encode
|
||||
import rate_limit 60
|
||||
header Age 10
|
||||
header Cache-Control "max-age=300"
|
||||
route / {
|
||||
root /data/www
|
||||
file_server
|
||||
import cache 0s 24h
|
||||
}
|
||||
route /favicon.ico {
|
||||
root /data/www
|
||||
file_server
|
||||
import cache 0s 24h
|
||||
}
|
||||
handle_errors {
|
||||
@redirects `{err.status_code} in [301, 302, 307]`
|
||||
reverse_proxy @redirects {
|
||||
header_up Location {http.response.header.Location}
|
||||
}
|
||||
}
|
||||
|
||||
route /v2* {
|
||||
reverse_proxy https://registry-1.docker.io {
|
||||
header_up Host registry-1.docker.io
|
||||
header_up X-Real-IP {remote}
|
||||
header_up X-Forwarded-For {http.request.header.X-Forwarded-For}
|
||||
header_up X-Forwarded-Proto {scheme}
|
||||
header_up Authorization {http.request.header.Authorization}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import /data/caddy/config.d/*
|
||||
@@ -1,93 +0,0 @@
|
||||
{
|
||||
debug
|
||||
http_port 80
|
||||
https_port 443
|
||||
order cache before rewrite
|
||||
cache {
|
||||
cache_name GhProxyCache
|
||||
}
|
||||
log {
|
||||
level INFO
|
||||
output file /data/caddy/log/caddy.log {
|
||||
roll_size 5MB
|
||||
roll_keep 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(log) {
|
||||
log {
|
||||
format transform `{request>headers>X-Forwarded-For>[0]:request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` {
|
||||
time_format "02/Jan/2006:15:04:05 -0700"
|
||||
}
|
||||
output file /data/caddy/log/{args[0]}/access.log {
|
||||
roll_size 5MB
|
||||
roll_keep 10
|
||||
roll_keep_for 24h
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(error_page) {
|
||||
handle_errors {
|
||||
rewrite * /{err.status_code}.html
|
||||
root * /data/caddy/pages/errors
|
||||
file_server
|
||||
}
|
||||
}
|
||||
|
||||
(encode) {
|
||||
encode {
|
||||
zstd best
|
||||
br 5 v2
|
||||
gzip 5
|
||||
minimum_length 512
|
||||
}
|
||||
}
|
||||
|
||||
(cache) {
|
||||
cache {
|
||||
allowed_http_verbs GET
|
||||
stale {args[0]}
|
||||
ttl {args[1]}
|
||||
}
|
||||
}
|
||||
|
||||
(header_realip) {
|
||||
header_up X-Real-IP {remote_host}
|
||||
header_up X-Real-IP {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP}
|
||||
header_up X-Forwarded-Proto {http.request.header.CF-Visitor}
|
||||
}
|
||||
|
||||
(rate_limit) {
|
||||
route /* {
|
||||
rate_limit {remote.ip} {args[0]}r/m 10000 429
|
||||
}
|
||||
}
|
||||
|
||||
:80 {
|
||||
reverse_proxy {
|
||||
to 127.0.0.1:8080
|
||||
import header_realip
|
||||
}
|
||||
import log ghproxy
|
||||
import cache 0s 300s
|
||||
import error_page
|
||||
import encode
|
||||
route /* {
|
||||
rate_limit {remote.ip} 60r/m 10000 429
|
||||
}
|
||||
route / {
|
||||
root /data/www
|
||||
file_server
|
||||
import cache 0s 24h
|
||||
}
|
||||
route /favicon.ico {
|
||||
root /data/www
|
||||
file_server
|
||||
import cache 0s 24h
|
||||
}
|
||||
}
|
||||
|
||||
import /data/caddy/config.d/*
|
||||
@@ -6,22 +6,32 @@ import (
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig
|
||||
Pages PagesConfig
|
||||
Log LogConfig
|
||||
CORS CORSConfig
|
||||
Auth AuthConfig
|
||||
Blacklist BlacklistConfig
|
||||
Whitelist WhitelistConfig
|
||||
RateLimit RateLimitConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port int `toml:"port"`
|
||||
Host string `toml:"host"`
|
||||
SizeLimit int `toml:"sizelimit"`
|
||||
SizeLimit int `toml:"sizeLimit"`
|
||||
EnableH2C string `toml:"enableH2C"`
|
||||
Debug bool `toml:"debug"`
|
||||
}
|
||||
|
||||
type PagesConfig struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
StaticDir string `toml:"staticDir"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
LogFilePath string `toml:"logfilepath"`
|
||||
MaxLogSize int `toml:"maxlogsize"`
|
||||
LogFilePath string `toml:"logFilePath"`
|
||||
MaxLogSize int `toml:"maxLogSize"`
|
||||
Level string `toml:"level"`
|
||||
}
|
||||
|
||||
type CORSConfig struct {
|
||||
@@ -29,18 +39,27 @@ type CORSConfig struct {
|
||||
}
|
||||
|
||||
type AuthConfig struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
AuthToken string `toml:"authtoken"`
|
||||
Enabled bool `toml:"enabled"`
|
||||
AuthMethod string `toml:"authMethod"`
|
||||
AuthToken string `toml:"authToken"`
|
||||
PassThrough bool `toml:"passThrough"`
|
||||
}
|
||||
|
||||
type BlacklistConfig struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
BlacklistFile string `toml:"blacklistfile"`
|
||||
BlacklistFile string `toml:"blacklistFile"`
|
||||
}
|
||||
|
||||
type WhitelistConfig struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
WhitelistFile string `toml:"whitelistfile"`
|
||||
WhitelistFile string `toml:"whitelistFile"`
|
||||
}
|
||||
|
||||
type RateLimitConfig struct {
|
||||
Enabled bool `toml:"enabled"`
|
||||
RateMethod string `toml:"rateMethod"`
|
||||
RatePerMinute int `toml:"ratePerMinute"`
|
||||
Burst int `toml:"burst"`
|
||||
}
|
||||
|
||||
// LoadConfig 从 TOML 配置文件加载配置
|
||||
|
||||
@@ -1,23 +1,38 @@
|
||||
[server]
|
||||
host = "127.0.0.1"
|
||||
host = "0.0.0.0"
|
||||
port = 8080
|
||||
sizelimit = 131072000 # 125MB
|
||||
sizeLimit = 125 # MB
|
||||
enableH2C = "on" # "on" or "off"
|
||||
debug = false
|
||||
|
||||
[pages]
|
||||
enabled = false
|
||||
staticDir = "/data/www"
|
||||
|
||||
[log]
|
||||
logfilepath = "/data/ghproxy/log/ghproxy.log"
|
||||
maxlogsize = 5 # MB
|
||||
logFilePath = "/data/ghproxy/log/ghproxy.log"
|
||||
maxLogSize = 5 # MB
|
||||
level = "info" # dump, debug, info, warn, error, none
|
||||
|
||||
[cors]
|
||||
enabled = true
|
||||
|
||||
[auth]
|
||||
authtoken = "test"
|
||||
authMethod = "parameters" # "header" or "parameters"
|
||||
authToken = "token"
|
||||
enabled = false
|
||||
passThrough = false
|
||||
|
||||
[blacklist]
|
||||
blacklistfile = "/data/ghproxy/config/blacklist.json"
|
||||
blacklistFile = "/data/ghproxy/config/blacklist.json"
|
||||
enabled = false
|
||||
|
||||
[whitelist]
|
||||
enabled = false
|
||||
whitelistfile = "/data/ghproxy/config/whitelist.json"
|
||||
whitelistFile = "/data/ghproxy/config/whitelist.json"
|
||||
|
||||
[rateLimit]
|
||||
enabled = false
|
||||
rateMethod = "total" # "ip" or "total"
|
||||
ratePerMinute = 180
|
||||
burst = 5
|
||||
|
||||
@@ -1,23 +1,38 @@
|
||||
[server]
|
||||
host = "127.0.0.1"
|
||||
port = 8080
|
||||
sizelimit = 131072000 # 125MB
|
||||
sizeLimit = 125 # MB
|
||||
enableH2C = false
|
||||
debug = false
|
||||
|
||||
[pages]
|
||||
enabled = false
|
||||
staticDir = "/usr/local/ghproxy/pages"
|
||||
level = "info"
|
||||
|
||||
[log]
|
||||
logfilepath = "/root/data/ghproxy/log/ghproxy.log"
|
||||
maxlogsize = 5 # MB
|
||||
logFilePath = "/usr/local/ghproxy/log/ghproxy.log"
|
||||
maxLogSize = 5 # MB
|
||||
|
||||
[cors]
|
||||
enabled = true
|
||||
|
||||
[auth]
|
||||
authtoken = "test"
|
||||
authMethod = "parameters" # "header" or "parameters"
|
||||
authToken = "token"
|
||||
enabled = false
|
||||
passThrough = false
|
||||
|
||||
[blacklist]
|
||||
blacklistfile = "/root/data/ghproxy/config/blacklist.json"
|
||||
blacklistFile = "/usr/local/ghproxy/config/blacklist.json"
|
||||
enabled = false
|
||||
|
||||
[whitelist]
|
||||
enabled = false
|
||||
whitelistfile = "/root/data/ghproxy/config/whitelist.json"
|
||||
whitelistFile = "/usr/local/ghproxy/config/whitelist.json"
|
||||
|
||||
[rateLimit]
|
||||
enabled = false
|
||||
rateMethod = "total" # "ip" or "total"
|
||||
ratePerMinute = 180
|
||||
burst = 5
|
||||
|
||||
@@ -3,8 +3,8 @@ Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '/root/data/ghproxy/ghproxy -cfg /root/data/ghproxy/config/config.toml > /root/data/ghproxy/log/run.log 2>&1'
|
||||
WorkingDirectory=/root/data/ghproxy
|
||||
ExecStart=/bin/bash -c '/usr/local/ghproxy/ghproxy -cfg /usr/local/ghproxy/config/config.toml > /usr/local/ghproxy/log/run.log 2>&1'
|
||||
WorkingDirectory=/usr/local/ghproxy
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# /bin/bash
|
||||
# https://github.com/WJQSERVER-STUDIO/ghproxy
|
||||
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
|
||||
# install packages
|
||||
install() {
|
||||
@@ -27,6 +30,14 @@ install() {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
# 检查是否为root用户
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "请以root用户运行此脚本"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 安装依赖包
|
||||
install curl wget sed
|
||||
|
||||
@@ -44,36 +55,88 @@ elif [ "$ARCH" == "aarch64" ]; then
|
||||
ARCH="arm64"
|
||||
fi
|
||||
|
||||
# 获取监听端口
|
||||
read -p "请输入程序监听的端口(默认8080): " PORT
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT=8080
|
||||
fi
|
||||
|
||||
# 本机监听/泛监听(127.0.0.1/0.0.0.0)
|
||||
read -p "请键入程序监听的IP(默认127.0.0.1)(0.0.0.0为泛监听): " IP
|
||||
if [ -z "$IP" ]; then
|
||||
IP="127.0.0.1"
|
||||
fi
|
||||
|
||||
# 安装目录
|
||||
read -p "请输入安装目录(默认/usr/local/ghproxy): " ghproxy_dir
|
||||
if [ -z "$ghproxy_dir" ]; then
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
make_systemd_service() {
|
||||
cat <<EOF > /etc/systemd/system/ghproxy.service
|
||||
[Unit]
|
||||
Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '$ghproxy_dir/ghproxy -cfg $ghproxy_dir/config/config.toml > $ghproxy_dir/log/run.log 2>&1'
|
||||
WorkingDirectory=$ghproxy_dir
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# 创建目录
|
||||
mkdir -p /root/data/ghproxy
|
||||
mkdir -p /root/data/ghproxy/config
|
||||
mkdir -p /root/data/ghproxy/log
|
||||
mkdir -p ${ghproxy_dir}
|
||||
mkdir -p ${ghproxy_dir}/config
|
||||
mkdir -p ${ghproxy_dir}/log
|
||||
mkdir -p ${ghproxy_dir}/pages
|
||||
|
||||
# 获取最新版本号
|
||||
VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION)
|
||||
wget -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION
|
||||
wget -q -O ${ghproxy_dir}/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION
|
||||
|
||||
# 下载ghproxy
|
||||
wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x /root/data/ghproxy/ghproxy
|
||||
wget -q -O ${ghproxy_dir}/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH.tar.gz
|
||||
install tar
|
||||
tar -zxvf ${ghproxy_dir}/ghproxy-linux-$ARCH.tar.gz -C ${ghproxy_dir}
|
||||
chmod +x ${ghproxy_dir}/ghproxy
|
||||
|
||||
# 下载pages
|
||||
wget -q -O ${ghproxy_dir}/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html
|
||||
wget -q -O ${ghproxy_dir}/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico
|
||||
|
||||
|
||||
# 下载配置文件
|
||||
if [ -f /root/data/ghproxy/config/config.toml ]; then
|
||||
if [ -f ${ghproxy_dir}/config/config.toml ]; then
|
||||
echo "配置文件已存在, 跳过下载"
|
||||
echo "[WARNING] 请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性"
|
||||
sleep 2
|
||||
else
|
||||
wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
wget -q -O ${ghproxy_dir}/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
fi
|
||||
|
||||
# 替换 port = 8080
|
||||
sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml
|
||||
sed -i "s/port = 8080/port = $PORT/g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i 's/host = "127.0.0.1"/host = "'"$IP"'"/g' ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|staticDir = \"/usr/local/ghproxy/pages\"|staticDir = \"${ghproxy_dir}/pages\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|logFilePath = \"/usr/local/ghproxy/log/ghproxy.log\"|logFilePath = \"${ghproxy_dir}/log/ghproxy.log\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|blacklistFile = \"/usr/local/ghproxy/config/blacklist.json\"|blacklistFile = \"${ghproxy_dir}/config/blacklist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|whitelistFile = \"/usr/local/ghproxy/config/whitelist.json\"|whitelistFile = \"${ghproxy_dir}/config/whitelist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
|
||||
# 下载systemd服务文件
|
||||
wget -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
if [ "$ghproxy_dir" = "/usr/local/ghproxy" ]; then
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
else
|
||||
make_systemd_service()
|
||||
fi
|
||||
|
||||
# 启动ghproxy
|
||||
systemctl daemon-reload
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# /bin/bash
|
||||
# https://github.com/WJQSERVER-STUDIO/ghproxy
|
||||
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
|
||||
# install packages
|
||||
install() {
|
||||
@@ -27,6 +30,14 @@ install() {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
# 检查是否为root用户
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "请以root用户运行此脚本"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 安装依赖包
|
||||
install curl wget sed
|
||||
|
||||
@@ -44,36 +55,88 @@ elif [ "$ARCH" == "aarch64" ]; then
|
||||
ARCH="arm64"
|
||||
fi
|
||||
|
||||
# 获取监听端口
|
||||
read -p "请输入程序监听的端口(默认8080): " PORT
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT=8080
|
||||
fi
|
||||
|
||||
# 本机监听/泛监听(127.0.0.1/0.0.0.0)
|
||||
read -p "请键入程序监听的IP(默认127.0.0.1)(0.0.0.0为泛监听): " IP
|
||||
if [ -z "$IP" ]; then
|
||||
IP="127.0.0.1"
|
||||
fi
|
||||
|
||||
# 安装目录
|
||||
read -p "请输入安装目录(默认/usr/local/ghproxy): " ghproxy_dir
|
||||
if [ -z "$ghproxy_dir" ]; then
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
make_systemd_service() {
|
||||
cat <<EOF > /etc/systemd/system/ghproxy.service
|
||||
[Unit]
|
||||
Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '$ghproxy_dir/ghproxy -cfg $ghproxy_dir/config/config.toml > $ghproxy_dir/log/run.log 2>&1'
|
||||
WorkingDirectory=$ghproxy_dir
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# 创建目录
|
||||
mkdir -p /root/data/ghproxy
|
||||
mkdir -p /root/data/ghproxy/config
|
||||
mkdir -p /root/data/ghproxy/log
|
||||
mkdir -p ${ghproxy_dir}
|
||||
mkdir -p ${ghproxy_dir}/config
|
||||
mkdir -p ${ghproxy_dir}/log
|
||||
mkdir -p ${ghproxy_dir}/pages
|
||||
|
||||
# 获取最新版本号
|
||||
VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION)
|
||||
wget -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION
|
||||
wget -q -O ${ghproxy_dir}/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION
|
||||
|
||||
# 下载ghproxy
|
||||
wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x /root/data/ghproxy/ghproxy
|
||||
wget -q -O ${ghproxy_dir}/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/${VERSION}/ghproxy-linux-${ARCH}.tar.gz
|
||||
install tar
|
||||
tar -zxvf ${ghproxy_dir}/ghproxy-linux-$ARCH.tar.gz -C ${ghproxy_dir}
|
||||
chmod +x ${ghproxy_dir}/ghproxy
|
||||
|
||||
# 下载pages
|
||||
wget -q -O ${ghproxy_dir}/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html
|
||||
wget -q -O ${ghproxy_dir}/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico
|
||||
|
||||
|
||||
# 下载配置文件
|
||||
if [ -f /root/data/ghproxy/config/config.toml ]; then
|
||||
if [ -f ${ghproxy_dir}/config/config.toml ]; then
|
||||
echo "配置文件已存在, 跳过下载"
|
||||
echo "[WARNING] 请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性"
|
||||
sleep 2
|
||||
else
|
||||
wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
wget -q -O ${ghproxy_dir}/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
fi
|
||||
|
||||
# 替换 port = 8080
|
||||
sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml
|
||||
sed -i "s/port = 8080/port = $PORT/g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i 's/host = "127.0.0.1"/host = "'"$IP"'"/g' ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|staticDir = \"/usr/local/ghproxy/pages\"|staticDir = \"${ghproxy_dir}/pages\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|logFilePath = \"/usr/local/ghproxy/log/ghproxy.log\"|logFilePath = \"${ghproxy_dir}/log/ghproxy.log\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|blacklistFile = \"/usr/local/ghproxy/config/blacklist.json\"|blacklistFile = \"${ghproxy_dir}/config/blacklist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|whitelistFile = \"/usr/local/ghproxy/config/whitelist.json\"|whitelistFile = \"${ghproxy_dir}/config/whitelist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
|
||||
# 下载systemd服务文件
|
||||
wget -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
if [ "$ghproxy_dir" = "/usr/local/ghproxy" ]; then
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
else
|
||||
make_systemd_service()
|
||||
fi
|
||||
|
||||
# 启动ghproxy
|
||||
systemctl daemon-reload
|
||||
|
||||
@@ -7,7 +7,21 @@ systemctl stop ghproxy
|
||||
systemctl disable ghproxy
|
||||
rm /etc/systemd/system/ghproxy.service
|
||||
|
||||
# 获取安装文件夹
|
||||
read -p "请输入 ghproxy 安装文件夹路径(默认 /usr/local/ghproxy): " install_path
|
||||
if [ -z "$install_path" ]; then
|
||||
install_path="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
# 删除 ghproxy 文件夹
|
||||
rm -r /root/data/ghproxy
|
||||
# 检查目录是否存在ghproxy文件
|
||||
if [ -f "$install_path" ]; then
|
||||
echo "ghproxy 未安装或安装路径错误"
|
||||
exit 1
|
||||
else
|
||||
echo "ghproxy 安装目录已确认,正在卸载..."
|
||||
rm -r $install_path
|
||||
fi
|
||||
|
||||
|
||||
echo "ghproxy 已成功卸载"
|
||||
@@ -8,4 +8,4 @@ services:
|
||||
- './ghproxy/log/caddy:/data/caddy/log'
|
||||
- './ghproxy/config:/data/ghproxy/config'
|
||||
ports:
|
||||
- '7210:80'
|
||||
- '7210:8080'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM wjqserver/caddy:daily-alpine AS builder
|
||||
FROM alpine:latest AS builder
|
||||
|
||||
ARG USER=WJQSERVER-STUDIO
|
||||
ARG REPO=ghproxy
|
||||
@@ -13,31 +13,34 @@ RUN mkdir -p /data/${APPLICATION}/config
|
||||
RUN mkdir -p /data/${APPLICATION}/log
|
||||
|
||||
# 安装依赖
|
||||
RUN apk add --no-cache curl wget
|
||||
RUN apk add --no-cache curl wget tar
|
||||
|
||||
# 前端
|
||||
RUN wget -O /data/www/index.html https://raw.githubusercontent.com/${USER}/${REPO}/main/pages/index.html
|
||||
RUN wget -O /data/www/favicon.ico https://raw.githubusercontent.com/${USER}/${REPO}/main/pages/favicon.ico
|
||||
RUN wget -O /data/www/index.html https://raw.githubusercontent.com/${USER}/${REPO}/dev/pages/index.html
|
||||
RUN wget -O /data/www/favicon.ico https://raw.githubusercontent.com/${USER}/${REPO}/dev/pages/favicon.ico
|
||||
|
||||
# 后端
|
||||
RUN VERSION=$(curl -s https://raw.githubusercontent.com/${USER}/${REPO}/main/DEV-VERSION) && \
|
||||
wget -O /data/${APPLICATION}/${APPLICATION} https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION}-${TARGETOS}-${TARGETARCH}
|
||||
RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${REPO}/main/docker/dockerfile/dev/init.sh
|
||||
RUN VERSION=$(curl -s https://raw.githubusercontent.com/${USER}/${REPO}/dev/DEV-VERSION) && \
|
||||
wget -O /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz && \
|
||||
tar -zxvf /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz -C /data/${APPLICATION} && \
|
||||
rm -rf /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz
|
||||
RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${REPO}/dev/docker/dockerfile/dev/init.sh
|
||||
|
||||
# 拉取配置
|
||||
RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${REPO}/main/caddyfile/dev/Caddyfile
|
||||
RUN wget -O /data/${APPLICATION}/config.toml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.toml
|
||||
RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/blacklist.json
|
||||
RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/whitelist.json
|
||||
#RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${REPO}/dev/caddyfile/dev/Caddyfile
|
||||
RUN wget -O /data/${APPLICATION}/config.toml https://raw.githubusercontent.com/${USER}/${REPO}/dev/config/config.toml
|
||||
RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/dev/config/blacklist.json
|
||||
RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.com/${USER}/${REPO}/dev/config/whitelist.json
|
||||
|
||||
# 权限
|
||||
RUN chmod +x /data/${APPLICATION}/${APPLICATION}
|
||||
RUN chmod +x /usr/local/bin/init.sh
|
||||
|
||||
FROM wjqserver/caddy:daily-alpine
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
COPY --from=builder /data/www /data/www
|
||||
COPY --from=builder /data/caddy /data/caddy
|
||||
COPY --from=builder /data/${APPLICATION} /data/${APPLICATION}
|
||||
COPY --from=builder /usr/local/bin/init.sh /usr/local/bin/init.sh
|
||||
|
||||
@@ -45,5 +48,4 @@ COPY --from=builder /usr/local/bin/init.sh /usr/local/bin/init.sh
|
||||
RUN chmod +x /data/${APPLICATION}/${APPLICATION}
|
||||
RUN chmod +x /usr/local/bin/init.sh
|
||||
|
||||
CMD ["/usr/local/bin/init.sh"]
|
||||
|
||||
CMD ["/usr/local/bin/init.sh"]
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
APPLICATION=ghproxy
|
||||
|
||||
if [ ! -f /data/caddy/config/Caddyfile ]; then
|
||||
cp /data/caddy/Caddyfile /data/caddy/config/Caddyfile
|
||||
fi
|
||||
|
||||
if [ ! -f /data/${APPLICATION}/config/blacklist.json ]; then
|
||||
cp /data/${APPLICATION}/blacklist.json /data/${APPLICATION}/config/blacklist.json
|
||||
fi
|
||||
@@ -18,10 +14,4 @@ if [ ! -f /data/${APPLICATION}/config/config.toml ]; then
|
||||
cp /data/${APPLICATION}/config.toml /data/${APPLICATION}/config/config.toml
|
||||
fi
|
||||
|
||||
/data/caddy/caddy run --config /data/caddy/config/Caddyfile > /data/${APPLICATION}/log/caddy.log 2>&1 &
|
||||
|
||||
/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.toml > /data/${APPLICATION}/log/run.log 2>&1 &
|
||||
|
||||
while true; do
|
||||
sleep 1
|
||||
done
|
||||
/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.toml > /data/${APPLICATION}/log/run.log 2>&1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM wjqserver/caddy:2.9.0-rc-alpine AS builder
|
||||
FROM alpine:latest AS builder
|
||||
|
||||
ARG USER=WJQSERVER-STUDIO
|
||||
ARG REPO=ghproxy
|
||||
@@ -13,7 +13,7 @@ RUN mkdir -p /data/${APPLICATION}/config
|
||||
RUN mkdir -p /data/${APPLICATION}/log
|
||||
|
||||
# 安装依赖
|
||||
RUN apk add --no-cache curl wget
|
||||
RUN apk add --no-cache curl wget tar
|
||||
|
||||
# 前端
|
||||
RUN wget -O /data/www/index.html https://raw.githubusercontent.com/${USER}/${REPO}/main/pages/index.html
|
||||
@@ -21,11 +21,13 @@ RUN wget -O /data/www/favicon.ico https://raw.githubusercontent.com/${USER}/${RE
|
||||
|
||||
# 后端
|
||||
RUN VERSION=$(curl -s https://raw.githubusercontent.com/${USER}/${REPO}/main/VERSION) && \
|
||||
wget -O /data/${APPLICATION}/${APPLICATION} https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION}-${TARGETOS}-${TARGETARCH}
|
||||
wget -O /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz && \
|
||||
tar -zxvf /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz -C /data/${APPLICATION} && \
|
||||
rm -rf /data/${APPLICATION}/${APPLICATION}-${TARGETOS}-${TARGETARCH}.tar.gz
|
||||
RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${REPO}/main/docker/dockerfile/release/init.sh
|
||||
|
||||
# 拉取配置
|
||||
RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${REPO}/main/caddyfile/release/Caddyfile
|
||||
#RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${REPO}/main/caddyfile/release/Caddyfile
|
||||
RUN wget -O /data/${APPLICATION}/config.toml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.toml
|
||||
RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/blacklist.json
|
||||
RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/whitelist.json
|
||||
@@ -34,10 +36,12 @@ RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.co
|
||||
RUN chmod +x /data/${APPLICATION}/${APPLICATION}
|
||||
RUN chmod +x /usr/local/bin/init.sh
|
||||
|
||||
FROM wjqserver/caddy:2.9.0-rc-alpine
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
COPY --from=builder /data/www /data/www
|
||||
COPY --from=builder /data/caddy /data/caddy
|
||||
#COPY --from=builder /data/caddy /data/caddy
|
||||
COPY --from=builder /data/${APPLICATION} /data/${APPLICATION}
|
||||
COPY --from=builder /usr/local/bin/init.sh /usr/local/bin/init.sh
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
APPLICATION=ghproxy
|
||||
|
||||
if [ ! -f /data/caddy/config/Caddyfile ]; then
|
||||
cp /data/caddy/Caddyfile /data/caddy/config/Caddyfile
|
||||
fi
|
||||
|
||||
if [ ! -f /data/${APPLICATION}/config/blacklist.json ]; then
|
||||
cp /data/${APPLICATION}/blacklist.json /data/${APPLICATION}/config/blacklist.json
|
||||
fi
|
||||
@@ -18,10 +14,4 @@ if [ ! -f /data/${APPLICATION}/config/config.toml ]; then
|
||||
cp /data/${APPLICATION}/config.toml /data/${APPLICATION}/config/config.toml
|
||||
fi
|
||||
|
||||
/data/caddy/caddy run --config /data/caddy/config/Caddyfile > /data/${APPLICATION}/log/caddy.log 2>&1 &
|
||||
|
||||
/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.toml > /data/${APPLICATION}/log/run.log 2>&1 &
|
||||
|
||||
while true; do
|
||||
sleep 1
|
||||
done
|
||||
/data/${APPLICATION}/${APPLICATION} -cfg /data/${APPLICATION}/config/config.toml > /data/${APPLICATION}/log/run.log 2>&1
|
||||
|
||||
51
go.mod
51
go.mod
@@ -1,54 +1,39 @@
|
||||
module ghproxy
|
||||
|
||||
go 1.23.2
|
||||
go 1.23.6
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0
|
||||
github.com/WJQSERVER-STUDIO/go-utils/logger v1.3.0
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/imroc/req/v3 v3.48.0
|
||||
golang.org/x/time v0.10.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/bytedance/sonic v1.12.3 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
||||
github.com/cloudflare/circl v1.5.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.12.8 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.3 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||
github.com/gin-contrib/sse v1.0.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.22.1 // indirect
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||
github.com/goccy/go-json v0.10.3 // indirect
|
||||
github.com/google/pprof v0.0.0-20241009165004-a3522334989c // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.24.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||
github.com/quic-go/qpack v0.5.1 // indirect
|
||||
github.com/quic-go/quic-go v0.47.0 // indirect
|
||||
github.com/refraction-networking/utls v1.6.7 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
golang.org/x/arch v0.11.0 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/net v0.30.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
golang.org/x/tools v0.26.0 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
golang.org/x/arch v0.14.0 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
111
go.sum
111
go.sum
@@ -1,60 +1,42 @@
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU=
|
||||
github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
||||
github.com/WJQSERVER-STUDIO/go-utils/logger v1.3.0 h1:rOvutC4zYfvtSGN2CNZrycjtq8dLpfu7ypy7tTEErPY=
|
||||
github.com/WJQSERVER-STUDIO/go-utils/logger v1.3.0/go.mod h1:oW884JCCPDU6c906LI0uKXndWLiRvjb9LkGYC2cqRO8=
|
||||
github.com/bytedance/sonic v1.12.8 h1:4xYRVRlXIgvSZ4e8iVTlMF5szgpXd4AfvuWgA8I8lgs=
|
||||
github.com/bytedance/sonic v1.12.8/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
|
||||
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
|
||||
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
|
||||
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
|
||||
github.com/bytedance/sonic/loader v0.2.3 h1:yctD0Q3v2NOGfSWPLPvG2ggA2kV6TS6s4wioyEqssH0=
|
||||
github.com/bytedance/sonic/loader v0.2.3/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
||||
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
||||
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
||||
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
|
||||
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
|
||||
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
|
||||
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/go-playground/validator/v10 v10.24.0 h1:KHQckvo8G6hlWnrPX4NJJ+aBfWNAE/HH+qdL2cBpCmg=
|
||||
github.com/go-playground/validator/v10 v10.24.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20241009165004-a3522334989c h1:NDovD0SMpBYXlE1zJmS1q55vWB/fUQBcPAqAboZSccA=
|
||||
github.com/google/pprof v0.0.0-20241009165004-a3522334989c/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/imroc/req/v3 v3.48.0 h1:IYuMGetuwLzOOTzDCquDqs912WNwpsPK0TBXWPIvoqg=
|
||||
github.com/imroc/req/v3 v3.48.0/go.mod h1:weam9gmyb00QnOtu6HXSnk44dNFkIUQb5QdMx13FeUU=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
|
||||
github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
@@ -65,62 +47,41 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
|
||||
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
|
||||
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
|
||||
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||
github.com/quic-go/quic-go v0.47.0 h1:yXs3v7r2bm1wmPTYNLKAAJTHMYkPEsfYJmTazXrCZ7Y=
|
||||
github.com/quic-go/quic-go v0.47.0/go.mod h1:3bCapYsJvXGZcipOHuu7plYtaV6tnF+z7wIFsU0WK9E=
|
||||
github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM=
|
||||
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
|
||||
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
|
||||
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
|
||||
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
|
||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
|
||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
|
||||
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
||||
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4=
|
||||
golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
12
init.sh
12
init.sh
@@ -2,10 +2,6 @@
|
||||
|
||||
APPLICATON=ghproxy
|
||||
|
||||
if [ ! -f /data/caddy/config/Caddyfile ]; then
|
||||
cp /data/caddy/Caddyfile /data/caddy/config/Caddyfile
|
||||
fi
|
||||
|
||||
if [ ! -f /data/${APPLICATON}/config/blacklist.json ]; then
|
||||
cp /data/${APPLICATON}/blacklist.json /data/${APPLICATON}/config/blacklist.json
|
||||
fi
|
||||
@@ -18,11 +14,5 @@ if [ ! -f /data/${APPLICATON}/config/config.yaml ]; then
|
||||
cp /data/${APPLICATON}/config.yaml /data/${APPLICATON}/config/config.yaml
|
||||
fi
|
||||
|
||||
/data/caddy/caddy run --config /data/caddy/config/Caddyfile > /data/${APPLICATON}/log/caddy.log 2>&1 &
|
||||
|
||||
/data/${APPLICATON}/${APPLICATON} > /data/${APPLICATON}/log/run.log 2>&1 &
|
||||
|
||||
while [[ true ]]; do
|
||||
sleep 1
|
||||
done
|
||||
/data/${APPLICATON}/${APPLICATON} > /data/${APPLICATON}/log/run.log 2>&1
|
||||
|
||||
|
||||
181
logger/logger.go
181
logger/logger.go
@@ -1,181 +0,0 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
logw = Logw
|
||||
logFile *os.File
|
||||
logger *log.Logger
|
||||
logChannel = make(chan string, 100)
|
||||
quitChannel = make(chan struct{})
|
||||
logFileMutex sync.Mutex // 保护 logFile 的互斥锁
|
||||
logFilePath = "/data/ghproxy/log/ghproxy.log"
|
||||
)
|
||||
|
||||
// Init 初始化日志记录器,接受日志文件路径作为参数
|
||||
func Init(logFilePath_input string, maxLogsize int) error {
|
||||
logFileMutex.Lock()
|
||||
defer logFileMutex.Unlock()
|
||||
|
||||
var err error
|
||||
logFilePath = logFilePath_input
|
||||
logFile, err = os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger = log.New(logFile, "", 0)
|
||||
|
||||
go logWorker()
|
||||
go monitorLogSize(logFilePath, maxLogsize)
|
||||
return nil
|
||||
}
|
||||
|
||||
// logWorker 处理日志记录
|
||||
func logWorker() {
|
||||
for {
|
||||
select {
|
||||
case msg := <-logChannel:
|
||||
timestamp := time.Now().Format("02/Jan/2006:15:04:05 -0700")
|
||||
logger.Println(timestamp + " - " + msg)
|
||||
case <-quitChannel:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log 直接记录日志的函数
|
||||
func Log(customMessage string) {
|
||||
logChannel <- customMessage
|
||||
}
|
||||
|
||||
// Logw 用于格式化日志记录
|
||||
func Logw(format string, args ...interface{}) {
|
||||
message := fmt.Sprintf(format, args...)
|
||||
Log(message)
|
||||
}
|
||||
|
||||
// 日志等级INFO
|
||||
func LogInfo(format string, args ...interface{}) {
|
||||
message := fmt.Sprintf(format, args...)
|
||||
output := fmt.Sprintf("[INFO] %s", message)
|
||||
Log(output)
|
||||
}
|
||||
|
||||
// 日志等级WARNING
|
||||
func LogWarning(format string, args ...interface{}) {
|
||||
message := fmt.Sprintf(format, args...)
|
||||
output := fmt.Sprintf("[WARNING] %s", message)
|
||||
Log(output)
|
||||
}
|
||||
|
||||
// 日志等级ERROR
|
||||
func LogError(format string, args ...interface{}) {
|
||||
message := fmt.Sprintf(format, args...)
|
||||
Log(message)
|
||||
}
|
||||
|
||||
// Close 关闭日志文件
|
||||
func Close() {
|
||||
logFileMutex.Lock()
|
||||
defer logFileMutex.Unlock()
|
||||
|
||||
if logFile != nil {
|
||||
quitChannel <- struct{}{}
|
||||
if err := logFile.Close(); err != nil {
|
||||
fmt.Printf("Error closing log file: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func monitorLogSize(logFilePath string, maxLogsize int) {
|
||||
var maxLogsizeBytes int64 = int64(maxLogsize) * 1024 * 1024 // 最大日志文件大小,单位为MB
|
||||
for {
|
||||
time.Sleep(600 * time.Second) // 每10分钟检查一次
|
||||
logFileMutex.Lock()
|
||||
info, err := logFile.Stat()
|
||||
logFileMutex.Unlock()
|
||||
|
||||
if err == nil && info.Size() > maxLogsizeBytes {
|
||||
if err := rotateLogFile(logFilePath); err != nil {
|
||||
logw("Log Rotation Failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func rotateLogFile(logFilePath string) error {
|
||||
logFileMutex.Lock()
|
||||
defer logFileMutex.Unlock()
|
||||
|
||||
if logFile != nil {
|
||||
if err := logFile.Close(); err != nil {
|
||||
logw("Error closing log file for rotation: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 打开当前日志文件
|
||||
logFile, err := os.Open(logFilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open log file: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
defer logFile.Close()
|
||||
|
||||
newLogFilePath := logFilePath + "-" + time.Now().Format("20060102-150405") + ".tar.gz"
|
||||
outFile, err := os.Create(newLogFilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create gz file: %s, error: %w", newLogFilePath, err)
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
gzWriter, err := gzip.NewWriterLevel(outFile, gzip.BestCompression)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create gz writer: %w", err)
|
||||
}
|
||||
defer gzWriter.Close()
|
||||
|
||||
tarWriter := tar.NewWriter(gzWriter)
|
||||
defer tarWriter.Close()
|
||||
|
||||
logFileStat, err := logFile.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to stat log file: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
|
||||
logFileHeader := &tar.Header{
|
||||
Name: filepath.Base(logFilePath),
|
||||
Size: logFileStat.Size(),
|
||||
Mode: 0644,
|
||||
ModTime: logFileStat.ModTime(),
|
||||
}
|
||||
|
||||
if err := tarWriter.WriteHeader(logFileHeader); err != nil {
|
||||
return fmt.Errorf("failed to write log file header: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
|
||||
if _, err := io.Copy(tarWriter, logFile); err != nil {
|
||||
return fmt.Errorf("failed to copy log file: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
|
||||
if err := os.Truncate(logFilePath, 0); err != nil {
|
||||
return fmt.Errorf("failed to truncate log file: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
|
||||
// 重新打开日志文件
|
||||
logFile, err = os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reopen log file: %s, error: %w", logFilePath, err)
|
||||
}
|
||||
logger.SetOutput(logFile)
|
||||
|
||||
return nil
|
||||
}
|
||||
34
loggin/loggin.go
Normal file
34
loggin/loggin.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package loggin
|
||||
|
||||
import (
|
||||
"ghproxy/timing"
|
||||
"time"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
// 日志中间件
|
||||
func Middleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 处理请求
|
||||
c.Next()
|
||||
|
||||
var timingResults time.Duration
|
||||
|
||||
// 获取计时结果
|
||||
timingResults, _ = timing.Get(c)
|
||||
|
||||
// 记录日志 IP METHOD URL USERAGENT PROTOCOL STATUS TIMING
|
||||
logInfo("%s %s %s %s %d %s ", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Writer.Status(), timingResults)
|
||||
}
|
||||
}
|
||||
156
main.go
156
main.go
@@ -1,16 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"ghproxy/api"
|
||||
"ghproxy/auth"
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
"ghproxy/loggin"
|
||||
"ghproxy/proxy"
|
||||
"ghproxy/rate"
|
||||
"ghproxy/timing"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -20,87 +27,160 @@ var (
|
||||
router *gin.Engine
|
||||
configfile = "/data/ghproxy/config/config.toml"
|
||||
cfgfile string
|
||||
version string
|
||||
dev string
|
||||
runMode string
|
||||
limiter *rate.RateLimiter
|
||||
iplimiter *rate.IPRateLimiter
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed pages/*
|
||||
pagesFS embed.FS
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
LogWarning = logger.LogWarning
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
func ReadFlag() {
|
||||
func readFlag() {
|
||||
flag.StringVar(&cfgfile, "cfg", configfile, "config file path")
|
||||
}
|
||||
|
||||
func loadConfig() {
|
||||
var err error
|
||||
// 初始化配置
|
||||
cfg, err = config.LoadConfig(cfgfile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config: %v", err)
|
||||
fmt.Printf("Failed to load config: %v\n", err)
|
||||
}
|
||||
if cfg.Server.Debug {
|
||||
fmt.Println("Config File Path: ", cfgfile)
|
||||
fmt.Printf("Loaded config: %v\n", cfg)
|
||||
}
|
||||
fmt.Println("Config File Path: ", cfgfile)
|
||||
fmt.Printf("Loaded config: %v\n", cfg)
|
||||
}
|
||||
|
||||
func setupLogger(cfg *config.Config) {
|
||||
// 初始化日志模块
|
||||
var err error
|
||||
err = logger.Init(cfg.Log.LogFilePath, cfg.Log.MaxLogSize) // 传递日志文件路径
|
||||
err = logger.Init(cfg.Log.LogFilePath, cfg.Log.MaxLogSize)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize logger: %v", err)
|
||||
fmt.Printf("Failed to initialize logger: %v\n", err)
|
||||
}
|
||||
logInfo("Config File Path: ", cfgfile)
|
||||
logInfo("Loaded config: %v\n", cfg)
|
||||
err = logger.SetLogLevel(cfg.Log.Level)
|
||||
if err != nil {
|
||||
fmt.Printf("Logger Level Error: %v\n", err)
|
||||
}
|
||||
fmt.Printf("Log Level: %s\n", cfg.Log.Level)
|
||||
logDebug("Config File Path: ", cfgfile)
|
||||
logDebug("Loaded config: %v\n", cfg)
|
||||
logInfo("Init Completed")
|
||||
}
|
||||
|
||||
func Loadlist(cfg *config.Config) {
|
||||
func loadlist(cfg *config.Config) {
|
||||
auth.Init(cfg)
|
||||
}
|
||||
|
||||
func setupApi(cfg *config.Config, router *gin.Engine) {
|
||||
// 注册 API 接口
|
||||
api.InitHandleRouter(cfg, router)
|
||||
func setupApi(cfg *config.Config, router *gin.Engine, version string) {
|
||||
api.InitHandleRouter(cfg, router, version)
|
||||
}
|
||||
|
||||
func setupRateLimit(cfg *config.Config) {
|
||||
if cfg.RateLimit.Enabled {
|
||||
if cfg.RateLimit.RateMethod == "ip" {
|
||||
iplimiter = rate.NewIPRateLimiter(cfg.RateLimit.RatePerMinute, cfg.RateLimit.Burst, 1*time.Minute)
|
||||
} else if cfg.RateLimit.RateMethod == "total" {
|
||||
limiter = rate.New(cfg.RateLimit.RatePerMinute, cfg.RateLimit.Burst, 1*time.Minute)
|
||||
} else {
|
||||
logError("Invalid RateLimit Method: %s", cfg.RateLimit.RateMethod)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func InitReq() {
|
||||
proxy.InitReq()
|
||||
}
|
||||
|
||||
func init() {
|
||||
ReadFlag()
|
||||
readFlag()
|
||||
flag.Parse()
|
||||
loadConfig()
|
||||
setupLogger(cfg)
|
||||
Loadlist(cfg)
|
||||
InitReq()
|
||||
loadlist(cfg)
|
||||
setupRateLimit(cfg)
|
||||
|
||||
// 设置 Gin 模式
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
if cfg.Server.Debug {
|
||||
dev = "true"
|
||||
version = "dev"
|
||||
}
|
||||
if dev == "true" {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
runMode = "dev"
|
||||
} else {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
runMode = "release"
|
||||
}
|
||||
|
||||
// 初始化路由
|
||||
router = gin.Default()
|
||||
logDebug("Run Mode: %s", runMode)
|
||||
|
||||
setupApi(cfg, router)
|
||||
gin.LoggerWithWriter(io.Discard)
|
||||
router = gin.New()
|
||||
|
||||
// 定义路由
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
// 返回403错误
|
||||
c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.")
|
||||
// 记录访问者IP UA METHOD
|
||||
LogWarning("Forbidden: IP:%s UA:%s METHOD:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method)
|
||||
})
|
||||
// 添加recovery中间件
|
||||
router.Use(gin.Recovery())
|
||||
|
||||
// 添加log中间件
|
||||
router.Use(loggin.Middleware())
|
||||
|
||||
// 添加计时中间件
|
||||
router.Use(timing.Middleware())
|
||||
|
||||
//H2C默认值为true,而后遵循cfg.Server.EnableH2C的设置
|
||||
if cfg.Server.EnableH2C == "on" {
|
||||
router.UseH2C = true
|
||||
} else if cfg.Server.EnableH2C == "" {
|
||||
router.UseH2C = true
|
||||
} else {
|
||||
router.UseH2C = false
|
||||
}
|
||||
|
||||
setupApi(cfg, router, version)
|
||||
|
||||
if cfg.Pages.Enabled {
|
||||
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)
|
||||
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.File(indexPagePath)
|
||||
logInfo("IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto)
|
||||
})
|
||||
router.StaticFile("/favicon.ico", faviconPath)
|
||||
} else if !cfg.Pages.Enabled {
|
||||
pages, err := fs.Sub(pagesFS, "pages")
|
||||
if err != nil {
|
||||
logError("Failed when processing pages: %s", err)
|
||||
}
|
||||
router.GET("/", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||
router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages))))
|
||||
}
|
||||
|
||||
// 未匹配路由处理
|
||||
router.NoRoute(func(c *gin.Context) {
|
||||
proxy.NoRouteHandler(cfg)(c)
|
||||
proxy.NoRouteHandler(cfg, limiter, iplimiter, runMode)(c)
|
||||
})
|
||||
|
||||
fmt.Printf("GHProxy Version: %s\n", version)
|
||||
fmt.Printf("A Go Based High-Performance Github Proxy \n")
|
||||
fmt.Printf("Made by WJQSERVER-STUDIO\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// 启动服务器
|
||||
err := router.Run(fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port))
|
||||
if err != nil {
|
||||
logError("Error starting server: %v\n", err)
|
||||
logError("Failed to start server: %v\n", err)
|
||||
}
|
||||
|
||||
fmt.Println("Program finished")
|
||||
defer logger.Close()
|
||||
fmt.Println("Program Exit")
|
||||
}
|
||||
|
||||
605
pages/index.html
605
pages/index.html
@@ -4,276 +4,437 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Github文件加速">
|
||||
<title>Github文件加速</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://font.sec.miui.com/font/css?family=MiSans:400,700:MiSans">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<style>
|
||||
/* 通用样式 */
|
||||
:root {
|
||||
--primary-color: #007aff;
|
||||
/* 主要按钮颜色 */
|
||||
--secondary-color: #34c759;
|
||||
/* 次要按钮颜色 */
|
||||
--background-color: #f9f9f9;
|
||||
/* 亮色模式背景 */
|
||||
--card-background: #ffffff;
|
||||
/* 卡片背景 */
|
||||
--text-color: #333333;
|
||||
/* 亮色模式文本颜色 */
|
||||
--border-color: #e0e0e0;
|
||||
/* 边框颜色 */
|
||||
--input-background: #ffffff;
|
||||
/* 输入框背景 */
|
||||
--input-border: #d1d1d6;
|
||||
/* 输入框边框 */
|
||||
--pre-background: #f1f3f4;
|
||||
/* 代码块背景 */
|
||||
--pre-text-color: #333333;
|
||||
/* 代码块文本颜色 */
|
||||
--version-badge-hover: #39c5bb;
|
||||
/* 说明文字颜色 */
|
||||
--muted-text-color: #6c757d;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #f8f9fac5;
|
||||
font-family: 'Misans', Arial, sans-serif;
|
||||
padding: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
min-height: 100vh;
|
||||
background-color: var(--background-color);
|
||||
color: var(--text-color);
|
||||
font-family: sans-serif;
|
||||
line-height: 1.8;
|
||||
font-size: 15px;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
text-align: center;
|
||||
min-height: 45vh;
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: var(--text-color);
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.5px;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: bold;
|
||||
margin-bottom: 75px;
|
||||
p, span, a, li {
|
||||
color: var(--text-color);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.rounded-button {
|
||||
border-radius: 6px;
|
||||
transition: background-color 0.3s, transform 0.2s;
|
||||
padding: 10px 30px;
|
||||
background-color: #39c5bb;
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #0056b3;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: var(--card-background);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
margin: 16px 0;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
.btn-outline-secondary {
|
||||
border-radius: 50%;
|
||||
padding: 6px;
|
||||
transition: #e9e9e9 0.3s ease-in-out, color 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.btn-outline-secondary:hover {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.rounded-button:hover {
|
||||
background-color: #39c5bcda;
|
||||
transform: scale(1.05);
|
||||
.form-control {
|
||||
background-color: var(--input-background);
|
||||
border: 1px solid var(--input-border);
|
||||
color: var(--text-color);
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.tips>p:first-child::before {
|
||||
position: sticky;
|
||||
color: #7b7b7b;
|
||||
margin-bottom: 5px;
|
||||
.form-control:focus {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.3);
|
||||
}
|
||||
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
.text-muted {
|
||||
color: var(--muted-text-color) !important;
|
||||
}
|
||||
|
||||
.bg-light {
|
||||
background-color: var(--card-background) !important;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #2d2d2d;
|
||||
color: #f8f8f2;
|
||||
padding: 20px 20px;
|
||||
margin: 10px 0;
|
||||
background-color: var(--pre-background);
|
||||
color: var(--pre-text-color);
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: " ";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background: #ff5f56;
|
||||
border-radius: 50%;
|
||||
box-shadow: 20px 0 0 #ffbd2e, 40px 0 0 #27c93f;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
font-size: 0.875em;
|
||||
|
||||
}
|
||||
|
||||
.status-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.status-container p {
|
||||
margin: 0px 5px;
|
||||
}
|
||||
|
||||
|
||||
.code {
|
||||
position: relative;
|
||||
padding-right: 0px;
|
||||
}
|
||||
|
||||
.copy-button {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 10px;
|
||||
background: rgba(118, 119, 121, 0.7);
|
||||
.version-badge {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
background-color: var(--secondary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 5px 10px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s;
|
||||
z-index: 1;
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.8rem;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
transition: background-color 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
pre:hover .copy-button {
|
||||
opacity: 1;
|
||||
.version-badge:hover {
|
||||
background-color: var(--version-badge-hover);
|
||||
}
|
||||
|
||||
#visitor-info {
|
||||
margin-top: 10px;
|
||||
footer {
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
line-height: 0.5;
|
||||
color: var(--text-color);
|
||||
font-size: 0.9rem;
|
||||
background-color: var(--card-background);
|
||||
}
|
||||
|
||||
footer a {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
footer a:hover {
|
||||
color: #0056b3;
|
||||
}
|
||||
|
||||
/* 暗色模式 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background-color: #121212;
|
||||
/* 深灰色背景 */
|
||||
--card-background: #1e1e1e;
|
||||
/* 卡片背景稍浅 */
|
||||
--text-color: #ffffff;
|
||||
/* 纯白文本 */
|
||||
--primary-color: #0a84ff;
|
||||
/* 按钮蓝色 */
|
||||
--secondary-color: #30d158;
|
||||
/* 次要按钮绿色 */
|
||||
--border-color: #3a3a3a;
|
||||
/* 边框颜色 */
|
||||
--input-background: #2c2c2c;
|
||||
/* 输入框背景 */
|
||||
--input-border: #4a4a4a;
|
||||
/* 输入框边框 */
|
||||
--pre-background: #3b3636;
|
||||
/* 代码块背景 */
|
||||
--pre-text-color: #ffffff;
|
||||
/* 代码块文本颜色 */
|
||||
--version-badge-hover: #39c5bc9a;
|
||||
/* 说明文字颜色 */
|
||||
--muted-text-color: #a0a0a0;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--background-color);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
p,
|
||||
span,
|
||||
a,
|
||||
li {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: var(--card-background);
|
||||
color: var(--text-color);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.btn-outline-secondary {
|
||||
border-radius: 50%;
|
||||
padding: 6px;
|
||||
transition: background-color 0.3s ease-in-out, color 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.btn-outline-secondary:hover {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast {
|
||||
background-color: var(--card-background);
|
||||
color: var(--text-color);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.toast-body {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
|
||||
.form-control {
|
||||
background-color: var(--input-background);
|
||||
border: 1px solid var(--input-border);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.bg-light {
|
||||
background-color: var(--card-background) !important;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: var(--pre-background);
|
||||
color: var(--pre-text-color);
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: var(--card-background);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
footer a {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Github文件加速</h1>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" id="githubLinkInput" placeholder="键入Github链接">
|
||||
</div>
|
||||
<button class="btn rounded-button" id="formatButton">获取文件链接</button>
|
||||
|
||||
<div class="code" id="outputBlock">
|
||||
<button class="copy-button" id="copyButton" onclick="copyCode(this)">Copy</button>
|
||||
<pre id="formattedLinkOutput"></pre>
|
||||
</div>
|
||||
<div class="tips">
|
||||
<p>GitHub链接带不带协议头均可,支持release、archive以及文件,转换后链接均可使用</a>。</p>
|
||||
<div class="status-container">
|
||||
<p id="sizeLimitDisplay">文件大小限制: ...</p>
|
||||
<p id="whiteListStatus">白名单状态: ...</p>
|
||||
<p id="blackListStatus">黑名单状态: ...</p>
|
||||
<div class="container py-4 py-md-5">
|
||||
<main>
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h1 class="text-center mb-4">Github文件加速</h1>
|
||||
<p class="lead text-center mb-4">为访问Github文件进行加速</p>
|
||||
<form id="github-form">
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control form-control-lg" id="githubLinkInput"
|
||||
placeholder="请键入需要代理的 Github 链接">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-lg w-100">获取文件链接</button>
|
||||
</form>
|
||||
<div id="output" class="mt-3 bg-light p-3 rounded position-relative" style="display: none;">
|
||||
<pre id="formattedLinkOutput" class="mb-0"></pre>
|
||||
<button id="copyButton"
|
||||
class="btn btn-outline-secondary btn-sm position-absolute top-0 end-0 m-2" title="复制链接">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
|
||||
class="bi bi-clipboard" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z" />
|
||||
<path
|
||||
d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button id="openButton"
|
||||
class="btn btn-outline-secondary btn-sm position-absolute top-0 end-0 m-2 me-5"
|
||||
title="在新标签页中打开">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
|
||||
class="bi bi-box-arrow-up-right" viewBox="0 0 16 16">
|
||||
<path fill-rule="evenodd"
|
||||
d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z" />
|
||||
<path fill-rule="evenodd"
|
||||
d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-muted small mt-3 mb-0">GitHub 链接带不带协议头均可,支持 release、archive 以及文件,转换后链接均可使用。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">文件大小限制</h5>
|
||||
<p class="card-text" id="sizeLimitDisplay">...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">白名单状态</h5>
|
||||
<p class="card-text" id="whiteListStatus">...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">黑名单状态</h5>
|
||||
<p class="card-text" id="blackListStatus">...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer class="text-center mt-4">
|
||||
<p class="text-muted">
|
||||
Copyright © 2024-2025 WJQSERVER-STUDIO<br>
|
||||
<a href="https://github.com/WJQSERVER-STUDIO/ghproxy" class="text-decoration-none">GitHub 仓库</a> |
|
||||
<a href="https://t.me/ghproxy_go" class="text-decoration-none">Telegram 交流群</a>
|
||||
</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<div class="toast-container position-fixed top-0 end-0 p-3">
|
||||
<div id="toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-body"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function formatGithubLink() {
|
||||
var githubLinkInput = document.getElementById('githubLinkInput');
|
||||
var currentHost = window.location.host;
|
||||
var formattedLink = "";
|
||||
<div id="versionBadge" class="version-badge"></div>
|
||||
|
||||
if (githubLinkInput.value.startsWith("https://github.com/") || githubLinkInput.value.startsWith("http://github.com/")) {
|
||||
formattedLink = "https://" + currentHost + "/github.com" + githubLinkInput.value.substring(githubLinkInput.value.indexOf("/", 8));
|
||||
} else if (githubLinkInput.value.startsWith("github.com/")) {
|
||||
formattedLink = "https://" + currentHost + "/" + githubLinkInput.value;
|
||||
} else if (githubLinkInput.value.startsWith("https://raw.githubusercontent.com/") || githubLinkInput.value.startsWith("http://raw.githubusercontent.com/")) {
|
||||
formattedLink = "https://" + currentHost + githubLinkInput.value.substring(githubLinkInput.value.indexOf("/", 7));
|
||||
} else if (githubLinkInput.value.startsWith("raw.githubusercontent.com/")) {
|
||||
formattedLink = "https://" + currentHost + "/" + githubLinkInput.value;
|
||||
} else if (!githubLinkInput.value.trim()) {
|
||||
alert('请输入有效的GitHub链接');
|
||||
}
|
||||
var formattedLinkOutput = document.getElementById('formattedLinkOutput');
|
||||
formattedLinkOutput.textContent = formattedLink;
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
const githubForm = document.getElementById('github-form');
|
||||
const githubLinkInput = document.getElementById('githubLinkInput');
|
||||
const formattedLinkOutput = document.getElementById('formattedLinkOutput');
|
||||
const output = document.getElementById('output');
|
||||
const copyButton = document.getElementById('copyButton');
|
||||
const openButton = document.getElementById('openButton');
|
||||
const toast = new bootstrap.Toast(document.getElementById('toast'));
|
||||
|
||||
function showToast(message) {
|
||||
const toastBody = document.querySelector('.toast-body');
|
||||
toastBody.textContent = message;
|
||||
toast.show();
|
||||
}
|
||||
|
||||
document.getElementById('formatButton').addEventListener('click', formatGithubLink);
|
||||
document.getElementById('copyButton').addEventListener('click', function () {
|
||||
const output = document.getElementById('formattedLinkOutput');
|
||||
const range = document.createRange();
|
||||
range.selectNode(output);
|
||||
window.getSelection().removeAllRanges();
|
||||
window.getSelection().addRange(range);
|
||||
document.execCommand('copy');
|
||||
window.getSelection().removeAllRanges();
|
||||
alert('链接已复制到剪贴板');
|
||||
function formatGithubLink(githubLink) {
|
||||
const currentHost = window.location.host;
|
||||
let formattedLink = "";
|
||||
|
||||
if (githubLink.startsWith("https://github.com/") || githubLink.startsWith("http://github.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + "/github.com" + githubLink.substring(githubLink.indexOf("/", 8));
|
||||
} else if (githubLink.startsWith("github.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + "/" + githubLink;
|
||||
} else if (githubLink.startsWith("https://raw.githubusercontent.com/") || githubLink.startsWith("http://raw.githubusercontent.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + githubLink.substring(githubLink.indexOf("/", 7));
|
||||
} else if (githubLink.startsWith("raw.githubusercontent.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + "/" + githubLink;
|
||||
} else if (githubLink.startsWith("https://gist.githubusercontent.com/") || githubLink.startsWith("http://gist.githubusercontent.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + "/gist.github.com" + githubLink.substring(githubLink.indexOf("/", 18));
|
||||
} else if (githubLink.startsWith("gist.githubusercontent.com/")) {
|
||||
formattedLink = window.location.protocol + "//" + currentHost + "/" + githubLink;
|
||||
} else {
|
||||
showToast('请输入有效的GitHub链接');
|
||||
return null;
|
||||
}
|
||||
|
||||
return formattedLink;
|
||||
}
|
||||
|
||||
githubForm.addEventListener('submit', function (e) {
|
||||
e.preventDefault();
|
||||
const formattedLink = formatGithubLink(githubLinkInput.value);
|
||||
if (formattedLink) {
|
||||
formattedLinkOutput.textContent = formattedLink;
|
||||
output.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
function fetchSizeLimit() {
|
||||
fetch(window.location.origin + '/api/size_limit')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const sizeLimitDisplay = document.getElementById('sizeLimitDisplay');
|
||||
sizeLimitDisplay.textContent = `文件大小限制: ${data.MaxResponseBodySize} MB`;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching API:', error);
|
||||
copyButton.addEventListener('click', function () {
|
||||
navigator.clipboard.writeText(formattedLinkOutput.textContent).then(() => {
|
||||
showToast('链接已复制到剪贴板');
|
||||
});
|
||||
});
|
||||
|
||||
openButton.addEventListener('click', function () {
|
||||
window.open(formattedLinkOutput.textContent, '_blank');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
function fetchWhiteList() {
|
||||
fetch(window.location.origin + '/api/whitelist/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const whiteListStatus = document.getElementById('whiteListStatus');
|
||||
if (data.Whitelist) {
|
||||
whiteListStatus.textContent = `白名单状态: 已开启`;
|
||||
} else if (!data.Whitelist) {
|
||||
whiteListStatus.textContent = `白名单状态: 已关闭`;
|
||||
} else {
|
||||
whiteListStatus.textContent = `白名单状态: 未知`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching API:', error);
|
||||
});
|
||||
}
|
||||
function fetchBlackList() {
|
||||
fetch(window.location.origin + '/api/blacklist/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const blackListStatus = document.getElementById('blackListStatus');
|
||||
if (data.Blacklist) {
|
||||
blackListStatus.textContent = `黑名单状态: 已开启`;
|
||||
} else if (!data.Blacklist) {
|
||||
blackListStatus.textContent = `黑名单状态: 已关闭`;
|
||||
} else {
|
||||
blackListStatus.textContent = `黑名单状态: 未知`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching API:', error);
|
||||
});
|
||||
}
|
||||
function fetchAPI() {
|
||||
fetchSizeLimit();
|
||||
fetchWhiteList();
|
||||
fetchBlackList();
|
||||
fetch('/api/size_limit')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('sizeLimitDisplay').textContent = `${data.MaxResponseBodySize} MB`;
|
||||
});
|
||||
|
||||
fetch('/api/whitelist/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('whiteListStatus').textContent = data.Whitelist ? '已开启' : '已关闭';
|
||||
});
|
||||
|
||||
fetch('/api/blacklist/status')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('blackListStatus').textContent = data.Blacklist ? '已开启' : '已关闭';
|
||||
});
|
||||
|
||||
fetch('/api/version')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('versionBadge').textContent = data.Version;
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', fetchAPI);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
<footer>
|
||||
<p>
|
||||
Copyright © 2024 WJQSERVER-STUDIO
|
||||
</p>
|
||||
<p>
|
||||
GitHub仓库地址:<a href="https://github.com/WJQSERVER-STUDIO/ghproxy">https://github.com/WJQSERVER-STUDIO/ghproxy</a>
|
||||
</p>
|
||||
<div id="visitor-info" style="text-align: center; margin-top: 15px;">
|
||||
<p>您的IP地址: <span id="visitor-ip"></span></p>
|
||||
<p>当前位置: <span id="visitor-country"></span> <img id="visitor-flag" src="" alt="" width="24" height="16"></p>
|
||||
</div>
|
||||
<script>
|
||||
fetch('https://ip.1888866.xyz/ip-lookup')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('网络响应失败');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('visitor-ip').textContent = data.ip;
|
||||
document.getElementById('visitor-country').textContent = data.country_name;
|
||||
document.getElementById('visitor-flag').src = `https://flagcdn.com/w20/${data.country_code.toLowerCase()}.png`;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取地理位置信息失败:', error);
|
||||
const visitorInfo = document.getElementById('visitor-info');
|
||||
visitorInfo.innerHTML = '<p>无法获取您的地理位置信息,请稍后再试。</p>';
|
||||
});
|
||||
</script>
|
||||
</footer>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
37
proxy/authpass.go
Normal file
37
proxy/authpass.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"ghproxy/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func AuthPassThrough(c *gin.Context, cfg *config.Config, req *http.Request) {
|
||||
if cfg.Auth.PassThrough {
|
||||
token := c.Query("token")
|
||||
if token != "" {
|
||||
logDebug("%s %s %s %s %s Auth-PassThrough: token %s", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, token)
|
||||
switch cfg.Auth.AuthMethod {
|
||||
case "parameters":
|
||||
if !cfg.Auth.Enabled {
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
} else {
|
||||
logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
// 500 Internal Server Error
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Conflict Auth Method"})
|
||||
return
|
||||
}
|
||||
case "header":
|
||||
if cfg.Auth.Enabled {
|
||||
req.Header.Set("Authorization", "token "+token)
|
||||
}
|
||||
default:
|
||||
logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
// 500 Internal Server Error
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Invalid Auth Method / Auth Method is not be set"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
178
proxy/chunkreq.go
Normal file
178
proxy/chunkreq.go
Normal file
@@ -0,0 +1,178 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var BufferSize int = 32 * 1024 // 32KB
|
||||
|
||||
var (
|
||||
cclient *http.Client
|
||||
ctr *http.Transport
|
||||
BufferPool *sync.Pool
|
||||
)
|
||||
|
||||
func InitReq() {
|
||||
initChunkedHTTPClient()
|
||||
initGitHTTPClient()
|
||||
|
||||
// 初始化固定大小的缓存池
|
||||
BufferPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, BufferSize)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func initChunkedHTTPClient() {
|
||||
ctr = &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
MaxConnsPerHost: 60,
|
||||
IdleConnTimeout: 20 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
ResponseHeaderTimeout: 10 * time.Second,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
}
|
||||
cclient = &http.Client{
|
||||
Transport: ctr,
|
||||
}
|
||||
}
|
||||
|
||||
func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
|
||||
method := c.Request.Method
|
||||
|
||||
// 发送HEAD请求, 预获取Content-Length
|
||||
headReq, err := http.NewRequest("HEAD", u, nil)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, headReq)
|
||||
removeWSHeader(headReq) // 删除Conection Upgrade头, 避免与HTTP/2冲突(检查是否存在Upgrade头)
|
||||
AuthPassThrough(c, cfg, headReq)
|
||||
|
||||
headResp, err := cclient.Do(headReq)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
//defer headResp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
if err := Body.Close(); err != nil {
|
||||
logError("Failed to close response body: %v", err)
|
||||
}
|
||||
}(headResp.Body)
|
||||
|
||||
contentLength := headResp.Header.Get("Content-Length")
|
||||
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := headResp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if err := HandleResponseSize(headResp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
body, err := readRequestBody(c)
|
||||
if err != nil {
|
||||
HandleError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
bodyReader := bytes.NewBuffer(body)
|
||||
|
||||
// 创建请求
|
||||
req, err := http.NewRequest(method, u, bodyReader)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
setRequestHeaders(c, req)
|
||||
removeWSHeader(req) // 删除Conection Upgrade头, 避免与HTTP/2冲突(检查是否存在Upgrade头)
|
||||
AuthPassThrough(c, cfg, req)
|
||||
|
||||
resp, err := cclient.Do(req)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
/*
|
||||
if err := HandleResponseSize(resp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
contentLength = resp.Header.Get("Content-Length")
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for key, values := range resp.Header {
|
||||
for _, value := range values {
|
||||
c.Header(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
headersToRemove := map[string]struct{}{
|
||||
"Content-Security-Policy": {},
|
||||
"Referrer-Policy": {},
|
||||
"Strict-Transport-Security": {},
|
||||
}
|
||||
|
||||
for header := range headersToRemove {
|
||||
resp.Header.Del(header)
|
||||
}
|
||||
|
||||
if cfg.CORS.Enabled {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
} else {
|
||||
c.Header("Access-Control-Allow-Origin", "")
|
||||
}
|
||||
|
||||
c.Status(resp.StatusCode)
|
||||
|
||||
// 使用固定32KB缓冲池
|
||||
buffer := BufferPool.Get().([]byte)
|
||||
defer BufferPool.Put(buffer)
|
||||
|
||||
_, err = io.CopyBuffer(c.Writer, resp.Body, buffer)
|
||||
if err != nil {
|
||||
logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
} else {
|
||||
c.Writer.Flush() // 确保刷入
|
||||
}
|
||||
}
|
||||
145
proxy/gitreq.go
Normal file
145
proxy/gitreq.go
Normal file
@@ -0,0 +1,145 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var (
|
||||
gclient *http.Client
|
||||
gtr *http.Transport
|
||||
)
|
||||
|
||||
func initGitHTTPClient() {
|
||||
gtr = &http.Transport{
|
||||
MaxIdleConns: 30,
|
||||
MaxConnsPerHost: 30,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
}
|
||||
gclient = &http.Client{
|
||||
Transport: gtr,
|
||||
}
|
||||
}
|
||||
|
||||
func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
|
||||
method := c.Request.Method
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
|
||||
// 创建HTTP客户端
|
||||
//client := &http.Client{}
|
||||
|
||||
// 发送HEAD请求, 预获取Content-Length
|
||||
headReq, err := http.NewRequest("HEAD", u, nil)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, headReq)
|
||||
AuthPassThrough(c, cfg, headReq)
|
||||
|
||||
headResp, err := gclient.Do(headReq)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
// defer headResp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
if err := Body.Close(); err != nil {
|
||||
logError("Failed to close response body: %v", err)
|
||||
}
|
||||
}(headResp.Body)
|
||||
|
||||
contentLength := headResp.Header.Get("Content-Length")
|
||||
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := headResp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
body, err := readRequestBody(c)
|
||||
if err != nil {
|
||||
HandleError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
bodyReader := bytes.NewBuffer(body)
|
||||
|
||||
// 创建请求
|
||||
req, err := http.NewRequest(method, u, bodyReader)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, req)
|
||||
AuthPassThrough(c, cfg, req)
|
||||
|
||||
resp, err := gclient.Do(req)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
//defer resp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
if err := Body.Close(); err != nil {
|
||||
logError("Failed to close response body: %v", err)
|
||||
}
|
||||
}(resp.Body)
|
||||
|
||||
/*
|
||||
if err := HandleResponseSize(resp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
*/
|
||||
contentLength = resp.Header.Get("Content-Length")
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for key, values := range resp.Header {
|
||||
for _, value := range values {
|
||||
c.Header(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
headersToRemove := map[string]struct{}{
|
||||
"Content-Security-Policy": {},
|
||||
"Referrer-Policy": {},
|
||||
"Strict-Transport-Security": {},
|
||||
}
|
||||
|
||||
for header := range headersToRemove {
|
||||
resp.Header.Del(header)
|
||||
}
|
||||
|
||||
if cfg.CORS.Enabled {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
} else {
|
||||
c.Header("Access-Control-Allow-Origin", "")
|
||||
}
|
||||
|
||||
c.Status(resp.StatusCode)
|
||||
|
||||
if _, err := io.Copy(c.Writer, resp.Body); err != nil {
|
||||
logError("%s %s %s %s %s Response-Copy-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
}
|
||||
}
|
||||
131
proxy/handler.go
Normal file
131
proxy/handler.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/auth"
|
||||
"ghproxy/config"
|
||||
"ghproxy/rate"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *rate.IPRateLimiter, runMode string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
// 限制访问频率
|
||||
if cfg.RateLimit.Enabled {
|
||||
|
||||
var allowed bool
|
||||
|
||||
switch cfg.RateLimit.RateMethod {
|
||||
case "ip":
|
||||
allowed = iplimiter.Allow(c.ClientIP())
|
||||
case "total":
|
||||
allowed = limiter.Allow()
|
||||
default:
|
||||
logWarning("Invalid RateLimit Method")
|
||||
return
|
||||
}
|
||||
|
||||
if !allowed {
|
||||
c.JSON(http.StatusTooManyRequests, gin.H{"error": "Too Many Requests"})
|
||||
logWarning("%s %s %s %s %s 429-TooManyRequests", c.ClientIP(), c.Request.Method, c.Request.URL.RequestURI(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/") // 去掉前缀/
|
||||
re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`) // 匹配http://或https://开头的路径
|
||||
matches := re.FindStringSubmatch(rawPath) // 匹配路径
|
||||
|
||||
// 匹配路径错误处理
|
||||
if len(matches) < 3 {
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errMsg)
|
||||
c.String(http.StatusForbidden, "Invalid URL Format. Path: %s", rawPath)
|
||||
return
|
||||
}
|
||||
|
||||
// 制作url
|
||||
rawPath = "https://" + matches[2]
|
||||
|
||||
username, repo := MatchUserRepo(rawPath, cfg, c, matches) // 匹配用户名和仓库名
|
||||
|
||||
logInfo("%s %s %s %s %s Matched-Username: %s, Matched-Repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, username, repo)
|
||||
// dump log 记录详细信息 c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, full Header
|
||||
LogDump("%s %s %s %s %s %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, c.Request.Header)
|
||||
repouser := fmt.Sprintf("%s/%s", username, repo)
|
||||
|
||||
// 白名单检查
|
||||
if cfg.Whitelist.Enabled {
|
||||
whitelist := auth.CheckWhitelist(repouser, username, repo)
|
||||
if !whitelist {
|
||||
logErrMsg := fmt.Sprintf("%s %s %s %s %s Whitelist Blocked repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, repouser)
|
||||
errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", repouser)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
logWarning(logErrMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单检查
|
||||
if cfg.Blacklist.Enabled {
|
||||
blacklist := auth.CheckBlacklist(repouser, username, repo)
|
||||
if blacklist {
|
||||
logErrMsg := fmt.Sprintf("%s %s %s %s %s Blacklist Blocked repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, repouser)
|
||||
errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", repouser)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
logWarning(logErrMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
matches = CheckURL(rawPath, c)
|
||||
if matches == nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
logWarning("%s %s %s %s %s 404-NOMATCH", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
return
|
||||
}
|
||||
|
||||
// 若匹配api.github.com/repos/用户名/仓库名/路径, 则检查是否开启HeaderAuth
|
||||
if exps[5].MatchString(rawPath) {
|
||||
if cfg.Auth.AuthMethod != "header" || !cfg.Auth.Enabled {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "HeaderAuth is not enabled."})
|
||||
logError("%s %s %s %s %s HeaderAuth-Error: HeaderAuth is not enabled.", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 处理blob/raw路径
|
||||
if exps[1].MatchString(rawPath) {
|
||||
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
||||
}
|
||||
|
||||
// 鉴权
|
||||
authcheck, err := auth.AuthHandler(c, cfg)
|
||||
if !authcheck {
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
logWarning("%s %s %s %s %s Auth-Error: %v", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
// IP METHOD URL USERAGENT PROTO MATCHES
|
||||
logDebug("%s %s %s %s %s Matches: %v", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, matches)
|
||||
|
||||
switch {
|
||||
case exps[0].MatchString(rawPath), exps[1].MatchString(rawPath), exps[3].MatchString(rawPath), exps[4].MatchString(rawPath):
|
||||
//ProxyRequest(c, rawPath, cfg, "chrome", runMode)
|
||||
ChunkedProxyRequest(c, rawPath, cfg, "chrome", runMode) // dev test chunk
|
||||
case exps[2].MatchString(rawPath):
|
||||
//ProxyRequest(c, rawPath, cfg, "git", runMode)
|
||||
GitReq(c, rawPath, cfg, "git", runMode)
|
||||
default:
|
||||
c.String(http.StatusForbidden, "Invalid input.")
|
||||
fmt.Println("Invalid input.")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
34
proxy/matchrepo.go
Normal file
34
proxy/matchrepo.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 预定义regex
|
||||
var (
|
||||
pathRegex = regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`) // 匹配路径
|
||||
gistRegex = regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.*`) // 匹配gist路径
|
||||
)
|
||||
|
||||
// 提取用户名和仓库名
|
||||
func MatchUserRepo(rawPath string, cfg *config.Config, c *gin.Context, matches []string) (string, string) {
|
||||
if gistMatches := gistRegex.FindStringSubmatch(rawPath); len(gistMatches) == 3 {
|
||||
LogDump("%s %s %s %s %s Matched-Username: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, gistMatches[1])
|
||||
return gistMatches[1], ""
|
||||
}
|
||||
// 定义路径
|
||||
if pathMatches := pathRegex.FindStringSubmatch(matches[2]); len(pathMatches) >= 4 {
|
||||
return pathMatches[2], pathMatches[3]
|
||||
}
|
||||
|
||||
// 返回错误信息
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errMsg)
|
||||
c.String(http.StatusForbidden, "Invalid path; expected username/repo, Path: %s", rawPath)
|
||||
return "", ""
|
||||
}
|
||||
263
proxy/proxy.go
263
proxy/proxy.go
@@ -1,4 +1,3 @@
|
||||
// proxy/proxy.go 实验性
|
||||
package proxy
|
||||
|
||||
import (
|
||||
@@ -6,22 +5,18 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"ghproxy/auth"
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/imroc/req/v3"
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
LogWarning = logger.LogWarning
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
@@ -30,166 +25,23 @@ var exps = []*regexp.Regexp{
|
||||
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:blob|raw)/.*`),
|
||||
regexp.MustCompile(`^(?:https?://)?github\.com/([^/]+)/([^/]+)/(?:info|git-).*`),
|
||||
regexp.MustCompile(`^(?:https?://)?raw\.github(?:usercontent|)\.com/([^/]+)/([^/]+)/.+?/.+`),
|
||||
regexp.MustCompile(`^(?:https?://)?gist\.github\.com/([^/]+)/.+?/.+`),
|
||||
regexp.MustCompile(`^(?:https?://)?gist\.github(?:usercontent|)\.com/([^/]+)/.+?/.+`),
|
||||
regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`),
|
||||
}
|
||||
|
||||
func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
||||
re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`)
|
||||
matches := re.FindStringSubmatch(rawPath)
|
||||
|
||||
if len(matches) < 3 {
|
||||
LogWarning("Invalid URL: %s", rawPath)
|
||||
c.String(http.StatusForbidden, "Invalid URL.")
|
||||
return
|
||||
}
|
||||
|
||||
rawPath = "https://" + matches[2]
|
||||
|
||||
// 提取用户名和仓库名,格式为 handle/<username>/<repo>/*
|
||||
pathmatches := regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`)
|
||||
pathParts := pathmatches.FindStringSubmatch(matches[2])
|
||||
if len(pathParts) < 4 {
|
||||
LogWarning("Invalid path: %s", rawPath)
|
||||
c.String(http.StatusForbidden, "Invalid path; expected username/repo.")
|
||||
return
|
||||
}
|
||||
|
||||
username := pathParts[2]
|
||||
repo := pathParts[3]
|
||||
LogWarning("Blacklist Check > Username: %s, Repo: %s", username, repo)
|
||||
fullrepo := fmt.Sprintf("%s/%s", username, repo)
|
||||
|
||||
// 白名单检查
|
||||
if cfg.Whitelist.Enabled {
|
||||
whitelistpass := auth.CheckWhitelist(fullrepo)
|
||||
if !whitelistpass {
|
||||
errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
LogWarning(errMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单检查
|
||||
if cfg.Blacklist.Enabled {
|
||||
blacklistpass := auth.CheckBlacklist(fullrepo)
|
||||
if blacklistpass {
|
||||
errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
LogWarning(errMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
matches = CheckURL(rawPath)
|
||||
if matches == nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if exps[1].MatchString(rawPath) {
|
||||
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
||||
}
|
||||
|
||||
if !auth.AuthHandler(c, cfg) {
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
LogWarning("Unauthorized request: %s", rawPath)
|
||||
return
|
||||
}
|
||||
|
||||
logInfo("Matches: %v", matches)
|
||||
|
||||
switch {
|
||||
case exps[0].MatchString(rawPath), exps[1].MatchString(rawPath), exps[3].MatchString(rawPath), exps[4].MatchString(rawPath):
|
||||
logInfo("%s Matched - USE proxy-chrome", rawPath)
|
||||
ProxyRequest(c, rawPath, cfg, "chrome")
|
||||
case exps[2].MatchString(rawPath):
|
||||
logInfo("%s Matched - USE proxy-git", rawPath)
|
||||
ProxyRequest(c, rawPath, cfg, "git")
|
||||
default:
|
||||
c.String(http.StatusForbidden, "Invalid input.")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
||||
method := c.Request.Method
|
||||
// 记录 IP Method URL UA
|
||||
logInfo("%s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"))
|
||||
|
||||
client := createHTTPClient(mode)
|
||||
|
||||
body, err := readRequestBody(c)
|
||||
if err != nil {
|
||||
HandleError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
req := client.R().SetBody(body)
|
||||
setRequestHeaders(c, req)
|
||||
|
||||
resp, err := SendRequest(req, method, u)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := HandleResponseSize(resp, cfg, c); err != nil {
|
||||
LogWarning("Error handling response size: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
CopyResponseHeaders(resp, c, cfg)
|
||||
c.Status(resp.StatusCode)
|
||||
if err := copyResponseBody(c, resp.Body); err != nil {
|
||||
logError("Failed to copy response body: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// createHTTPClient 创建并配置 HTTP 客户端
|
||||
func createHTTPClient(mode string) *req.Client {
|
||||
client := req.C()
|
||||
switch mode {
|
||||
case "chrome":
|
||||
client.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36").
|
||||
SetTLSFingerprintChrome().
|
||||
ImpersonateChrome()
|
||||
case "git":
|
||||
client.SetUserAgent("git/2.33.1")
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
// readRequestBody 读取请求体
|
||||
// 读取请求体
|
||||
func readRequestBody(c *gin.Context) ([]byte, error) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
logError("failed to read request body: %v", err)
|
||||
return nil, fmt.Errorf("failed to read request body: %v", err)
|
||||
}
|
||||
defer c.Request.Body.Close()
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// setRequestHeaders 设置请求头
|
||||
func setRequestHeaders(c *gin.Context, req *req.Request) {
|
||||
for key, values := range c.Request.Header {
|
||||
for _, value := range values {
|
||||
req.SetHeader(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copyResponseBody 复制响应体到客户端
|
||||
func copyResponseBody(c *gin.Context, respBody io.Reader) error {
|
||||
_, err := io.Copy(c.Writer, respBody)
|
||||
return err
|
||||
}
|
||||
|
||||
func SendRequest(req *req.Request, method, url string) (*req.Response, error) {
|
||||
/*
|
||||
func SendRequest(c *gin.Context, req *req.Request, method, url string) (*req.Response, error) {
|
||||
switch method {
|
||||
case "GET":
|
||||
return req.Get(url)
|
||||
@@ -200,85 +52,44 @@ func SendRequest(req *req.Request, method, url string) (*req.Response, error) {
|
||||
case "DELETE":
|
||||
return req.Delete(url)
|
||||
default:
|
||||
logInfo("Unsupported method: %s", method)
|
||||
return nil, fmt.Errorf("unsupported method: %s", method)
|
||||
// IP METHOD URL USERAGENT PROTO UNSUPPORTED-METHOD
|
||||
errmsg := fmt.Sprintf("%s %s %s %s %s Unsupported method", c.ClientIP(), method, url, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errmsg)
|
||||
return nil, fmt.Errorf(errmsg)
|
||||
}
|
||||
}
|
||||
|
||||
func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context) error {
|
||||
contentLength := resp.Header.Get("Content-Length")
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > cfg.Server.SizeLimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
LogWarning("Size limit exceeded: %s, Size: %d", finalURL, size)
|
||||
return fmt.Errorf("size limit exceeded: %d", size)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) {
|
||||
removeHeaders(resp)
|
||||
|
||||
copyHeaders(resp, c)
|
||||
|
||||
setCORSHeaders(c, cfg)
|
||||
|
||||
setDefaultHeaders(c)
|
||||
}
|
||||
|
||||
// removeHeaders 移除指定的响应头
|
||||
func removeHeaders(resp *req.Response) {
|
||||
headersToRemove := map[string]struct{}{
|
||||
"Content-Security-Policy": {},
|
||||
"Referrer-Policy": {},
|
||||
"Strict-Transport-Security": {},
|
||||
}
|
||||
|
||||
for header := range headersToRemove {
|
||||
resp.Header.Del(header)
|
||||
}
|
||||
}
|
||||
|
||||
// copyHeaders 复制响应头到 Gin 上下文
|
||||
func copyHeaders(resp *req.Response, c *gin.Context) {
|
||||
for key, values := range resp.Header {
|
||||
for _, value := range values {
|
||||
c.Header(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setCORSHeaders 设置 CORS 相关的响应头
|
||||
func setCORSHeaders(c *gin.Context, cfg *config.Config) {
|
||||
if cfg.CORS.Enabled {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
} else {
|
||||
c.Header("Access-Control-Allow-Origin", "")
|
||||
}
|
||||
}
|
||||
|
||||
// setDefaultHeaders 设置默认的响应头
|
||||
func setDefaultHeaders(c *gin.Context) {
|
||||
c.Header("Age", "10")
|
||||
c.Header("Cache-Control", "max-age=300")
|
||||
}
|
||||
*/
|
||||
|
||||
func HandleError(c *gin.Context, message string) {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("server error %v", message))
|
||||
LogWarning(message)
|
||||
logError(message)
|
||||
}
|
||||
|
||||
func CheckURL(u string) []string {
|
||||
func CheckURL(u string, c *gin.Context) []string {
|
||||
for _, exp := range exps {
|
||||
if matches := exp.FindStringSubmatch(u); matches != nil {
|
||||
logInfo("URL matched: %s, Matches: %v", u, matches[1:])
|
||||
return matches[1:]
|
||||
}
|
||||
}
|
||||
errMsg := fmt.Sprintf("Invalid URL: %s", u)
|
||||
LogWarning(errMsg)
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logError(errMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
// 处理响应大小
|
||||
func HandleResponseSize(resp *http.Response, cfg *config.Config, c *gin.Context) error {
|
||||
contentLength := resp.Header.Get("Content-Length")
|
||||
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return fmt.Errorf("Path: %s size limit exceeded: %d", finalURL, size)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
79
proxy/proxyreq.go
Normal file
79
proxy/proxyreq.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package proxy
|
||||
|
||||
/*
|
||||
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
|
||||
method := c.Request.Method
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
|
||||
client := createHTTPClient(mode)
|
||||
if runMode == "dev" {
|
||||
client.DevMode()
|
||||
}
|
||||
|
||||
// 发送HEAD请求, 预获取Content-Length
|
||||
headReq := client.R()
|
||||
setRequestHeaders(c, headReq)
|
||||
AuthPassThrough(c, cfg, headReq)
|
||||
|
||||
headResp, err := headReq.Head(u)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer headResp.Body.Close()
|
||||
|
||||
if err := HandleResponseSize(headResp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := readRequestBody(c)
|
||||
if err != nil {
|
||||
HandleError(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
req := client.R().SetBody(body)
|
||||
setRequestHeaders(c, req)
|
||||
AuthPassThrough(c, cfg, req)
|
||||
|
||||
resp, err := SendRequest(c, req, method, u)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := HandleResponseSize(resp, cfg, c); err != nil {
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
CopyResponseHeaders(resp, c, cfg)
|
||||
c.Status(resp.StatusCode)
|
||||
if err := copyResponseBody(c, resp.Body); err != nil {
|
||||
logError("%s %s %s %s %s Response-Copy-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 复制响应体
|
||||
func copyResponseBody(c *gin.Context, respBody io.Reader) error {
|
||||
_, err := io.Copy(c.Writer, respBody)
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断并选择TLS指纹
|
||||
func createHTTPClient(mode string) *req.Client {
|
||||
client := req.C()
|
||||
switch mode {
|
||||
case "chrome":
|
||||
client.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36").
|
||||
SetTLSFingerprintChrome().
|
||||
ImpersonateChrome()
|
||||
case "git":
|
||||
client.SetUserAgent("git/2.33.1")
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
*/
|
||||
21
proxy/reqheader.go
Normal file
21
proxy/reqheader.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 设置请求头
|
||||
func setRequestHeaders(c *gin.Context, req *http.Request) {
|
||||
for key, values := range c.Request.Header {
|
||||
for _, value := range values {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removeWSHeader(req *http.Request) {
|
||||
req.Header.Del("Upgrade")
|
||||
req.Header.Del("Connection")
|
||||
}
|
||||
65
rate/rate.go
Normal file
65
rate/rate.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package rate
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/go-utils/logger"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
// 日志输出
|
||||
var (
|
||||
logw = logger.Logw
|
||||
LogDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
// 总体限流器
|
||||
type RateLimiter struct {
|
||||
limiter *rate.Limiter
|
||||
}
|
||||
|
||||
// 基于IP的限流器
|
||||
type IPRateLimiter struct {
|
||||
limiters map[string]*RateLimiter
|
||||
limit int
|
||||
burst int
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
func New(limit int, burst int, duration time.Duration) *RateLimiter {
|
||||
return &RateLimiter{
|
||||
limiter: rate.NewLimiter(rate.Limit(float64(limit)/duration.Seconds()), burst),
|
||||
}
|
||||
}
|
||||
|
||||
func (rl *RateLimiter) Allow() bool {
|
||||
return rl.limiter.Allow()
|
||||
}
|
||||
|
||||
func NewIPRateLimiter(limit int, burst int, duration time.Duration) *IPRateLimiter {
|
||||
return &IPRateLimiter{
|
||||
limiters: make(map[string]*RateLimiter),
|
||||
limit: limit,
|
||||
burst: burst,
|
||||
duration: duration,
|
||||
}
|
||||
}
|
||||
|
||||
func (rl *IPRateLimiter) Allow(ip string) bool {
|
||||
if ip == "" {
|
||||
logWarning("empty ip")
|
||||
return false
|
||||
}
|
||||
|
||||
limiter, ok := rl.limiters[ip]
|
||||
if !ok {
|
||||
// 创建新的 RateLimiter 并存储
|
||||
limiter = New(rl.limit, rl.burst, rl.duration)
|
||||
rl.limiters[ip] = limiter
|
||||
}
|
||||
return limiter.Allow()
|
||||
}
|
||||
86
timing/timing.go
Normal file
86
timing/timing.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package timing
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 阶段计时结构(固定数组优化)
|
||||
type timingData struct {
|
||||
phases [8]struct { // 预分配8个阶段存储
|
||||
name string
|
||||
dur time.Duration
|
||||
}
|
||||
count int
|
||||
start time.Time
|
||||
}
|
||||
|
||||
// 对象池(内存重用优化)
|
||||
var pool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return new(timingData)
|
||||
},
|
||||
}
|
||||
|
||||
// 中间件入口
|
||||
func Middleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 从池中获取计时器
|
||||
td := pool.Get().(*timingData)
|
||||
td.start = time.Now()
|
||||
td.count = 0
|
||||
|
||||
// 存储到上下文
|
||||
c.Set("timing", td)
|
||||
|
||||
// 请求完成后回收对象
|
||||
defer func() {
|
||||
pool.Put(td)
|
||||
}()
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 记录阶段耗时
|
||||
func Record(c *gin.Context, name string) {
|
||||
if val, exists := c.Get("timing"); exists {
|
||||
//td := val.(*timingData)
|
||||
td, ok := val.(*timingData)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if td.count < len(td.phases) {
|
||||
td.phases[td.count].name = name
|
||||
td.phases[td.count].dur = time.Since(td.start) // 直接记录当前时间
|
||||
td.count++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取计时结果(日志输出用)
|
||||
func Get(c *gin.Context) (total time.Duration, phases []struct {
|
||||
Name string
|
||||
Dur time.Duration
|
||||
}) {
|
||||
if val, exists := c.Get("timing"); exists {
|
||||
//td := val.(*timingData)
|
||||
td, ok := val.(*timingData)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for i := 0; i < td.count; i++ {
|
||||
phases = append(phases, struct {
|
||||
Name string
|
||||
Dur time.Duration
|
||||
}{
|
||||
Name: td.phases[i].name,
|
||||
Dur: td.phases[i].dur,
|
||||
})
|
||||
}
|
||||
total = time.Since(td.start)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user