diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 2095fea..5906659 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -12,7 +12,7 @@ jobs: prepare: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v3 - name: 加载版本号 run: | if [ -f DEV-VERSION ]; then @@ -21,7 +21,7 @@ jobs: echo "DEV-VERSION file not found!" && exit 1 fi - name: 输出版本号 - run: | + run: | echo "Version: ${{ env.VERSION }}" - name: 预先创建Pre-release id: create_release @@ -46,9 +46,10 @@ jobs: goarch: [amd64, arm64] env: OUTPUT_BINARY: ghproxy + GO_VERSION: 1.25 steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 with: ref: dev - name: 加载版本号 @@ -62,11 +63,11 @@ jobs: run: | sudo git clone https://github.com/WJQSERVER-STUDIO/GHProxy-Frontend.git pages sudo rm -rf pages/.git/ - + - name: 安装 Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v3 with: - go-version-file: go.mod + go-version: ${{ env.GO_VERSION }} - name: 编译 env: GOOS: ${{ matrix.goos }} @@ -82,7 +83,7 @@ jobs: tar -czf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz -C ghproxyd . ls - name: 上传Artifact - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@v4 with: name: ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} path: | @@ -99,8 +100,8 @@ jobs: prerelease: 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 @@ -108,10 +109,10 @@ jobs: IMAGE_NAME: wjqserver/ghproxy DOCKERFILE: docker/dockerfile/dev/Dockerfile DOCKERFILE_PATH: docker/dockerfile/dev - + steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v4 with: ref: dev - name: Load VERSION @@ -120,26 +121,26 @@ jobs: echo "VERSION=$(cat DEV-VERSION)" >> $GITHUB_ENV else echo "DEV-VERSION file not found!" && exit 1 - fi + fi - name: Set up QEMU - uses: docker/setup-qemu-action@v4 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: 构建镜像 - uses: docker/build-push-action@v7 + uses: docker/build-push-action@v6 with: file: ./${{ env.DOCKERFILE }} platforms: linux/amd64,linux/arm64 push: true - tags: | + tags: | ${{ env.IMAGE_NAME }}:${{ env.VERSION }} - ${{ env.IMAGE_NAME }}:dev + ${{ env.IMAGE_NAME }}:dev \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51208e9..c814dfb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,8 +12,8 @@ jobs: prepare: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 - with: + - uses: actions/checkout@v3 + with: ref: main - name: 加载版本号 run: | @@ -23,7 +23,7 @@ jobs: echo "VERSION file not found!" && exit 1 fi - name: 输出版本号 - run: | + run: | echo "Version: ${{ env.VERSION }}" - name: 预先创建release id: create_release @@ -40,16 +40,17 @@ jobs: build: runs-on: ubuntu-latest - needs: prepare + needs: prepare # 确保这个作业在 prepare 作业完成后运行 strategy: matrix: goos: [linux, darwin, freebsd] goarch: [amd64, arm64] env: OUTPUT_BINARY: ghproxy + GO_VERSION: 1.25 steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v3 with: ref: main - name: 加载版本号 @@ -63,11 +64,11 @@ jobs: run: | sudo git clone https://github.com/WJQSERVER-STUDIO/GHProxy-Frontend.git pages sudo rm -rf pages/.git/ - + - name: 安装 Go - uses: actions/setup-go@v6 + uses: actions/setup-go@v3 with: - go-version-file: go.mod + go-version: ${{ env.GO_VERSION }} - name: 编译 env: GOOS: ${{ matrix.goos }} @@ -82,11 +83,11 @@ jobs: cp LICENSE ./ghproxyd/ tar -czf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz -C ghproxyd . - name: 上传Artifact - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@v4 with: 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 @@ -102,14 +103,14 @@ jobs: docker: runs-on: ubuntu-latest - needs: build + needs: build # 确保这个作业在 build 作业完成后运行 env: - IMAGE_NAME: wjqserver/ghproxy - DOCKERFILE: docker/dockerfile/release/Dockerfile + IMAGE_NAME: wjqserver/ghproxy # 定义镜像名称变量 + DOCKERFILE: docker/dockerfile/release/Dockerfile # 定义 Dockerfile 路径变量 steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@v4 with: ref: main - name: Load VERSION @@ -121,26 +122,26 @@ jobs: fi - name: Set up QEMU - uses: docker/setup-qemu-action@v4 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 + uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub - uses: docker/login-action@v4 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: 构建镜像 - uses: docker/build-push-action@v7 + uses: docker/build-push-action@v6 with: file: ./${{ env.DOCKERFILE }} platforms: linux/amd64,linux/arm64 push: true - tags: | + tags: | ${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.IMAGE_NAME }}:v4 ${{ env.IMAGE_NAME }}:latest wjqserver/ghproxy-touka:latest - wjqserver/ghproxy-touka:${{ env.VERSION }} + wjqserver/ghproxy-touka:${{ env.VERSION }} \ No newline at end of file diff --git a/api/api.go b/api/api.go index c2f455c..b1bb61c 100644 --- a/api/api.go +++ b/api/api.go @@ -50,80 +50,84 @@ func InitHandleRouter(cfg *config.Config, r *touka.Engine, version string) { } func SizeLimitHandler(cfg *config.Config, c *touka.Context) { + sizeLimit := cfg.Server.SizeLimit c.SetHeader("Content-Type", "application/json") - c.JSON(200, SizeLimitResponse{ - MaxResponseBodySize: cfg.Server.SizeLimit, - }) + c.JSON(200, (map[string]interface{}{ + "MaxResponseBodySize": sizeLimit, + })) } func WhiteListStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, WhitelistStatusResponse{ - Whitelist: cfg.Whitelist.Enabled, - }) + c.JSON(200, (map[string]interface{}{ + "Whitelist": cfg.Whitelist.Enabled, + })) } func BlackListStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, BlacklistStatusResponse{ - Blacklist: cfg.Blacklist.Enabled, - }) + c.JSON(200, (map[string]interface{}{ + "Blacklist": cfg.Blacklist.Enabled, + })) } func CorsStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, CorsStatusResponse{ - Cors: cfg.Server.Cors, - }) + c.JSON(200, (map[string]interface{}{ + "Cors": cfg.Server.Cors, + })) } func HealthcheckHandler(c *touka.Context) { c.SetHeader("Content-Type", "application/json") - // 复制预定义的固定响应,避免重复分配 - resp := baseHealthcheckResponse - c.JSON(200, resp) + c.JSON(200, (map[string]interface{}{ + "Status": "OK", + "Repo": "WJQSERVER-STUDIO/GHProxy", + "Author": "WJQSERVER-STUDIO", + })) } func VersionHandler(c *touka.Context, version string) { c.SetHeader("Content-Type", "application/json") - // 复制预定义的固定响应并填充动态字段 - resp := baseVersionResponse - resp.Version = version - c.JSON(200, resp) + c.JSON(200, (map[string]interface{}{ + "Version": version, + "Repo": "WJQSERVER-STUDIO/GHProxy", + "Author": "WJQSERVER-STUDIO", + })) } func RateLimitStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, RateLimitStatusResponse{ - RateLimit: cfg.RateLimit.Enabled, - }) + c.JSON(200, (map[string]interface{}{ + "RateLimit": cfg.RateLimit.Enabled, + })) } func RateLimitLimitHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, RateLimitLimitResponse{ - RatePerMinute: cfg.RateLimit.RatePerMinute, - }) + c.JSON(200, (map[string]interface{}{ + "RatePerMinute": cfg.RateLimit.RatePerMinute, + })) } func SmartGitStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, SmartGitStatusResponse{ - Enabled: cfg.GitClone.Mode == "cache", - }) + c.JSON(200, (map[string]interface{}{ + "enabled": cfg.GitClone.Mode == "cache", + })) } func shellNestStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, ShellNestStatusResponse{ - Enabled: cfg.Shell.Editor, - }) + c.JSON(200, (map[string]interface{}{ + "enabled": cfg.Shell.Editor, + })) } func ociProxyStatusHandler(cfg *config.Config, c *touka.Context) { c.SetHeader("Content-Type", "application/json") - c.JSON(200, OCIDockerResponse{ - Enabled: cfg.Docker.Enabled, - Target: cfg.Docker.Target, - }) + c.JSON(200, (map[string]interface{}{ + "enabled": cfg.Docker.Enabled, + "target": cfg.Docker.Target, + })) } diff --git a/api/types.go b/api/types.go deleted file mode 100644 index fe052f7..0000000 --- a/api/types.go +++ /dev/null @@ -1,84 +0,0 @@ -package api - -// 预定义的固定响应内容,避免每次请求时创建 map - -// HealthcheckResponse 健康检查响应 -type HealthcheckResponse struct { - Status string `json:"Status"` - Repo string `json:"Repo"` - Author string `json:"Author"` -} - -// VersionResponse 版本信息响应 -type VersionResponse struct { - Version string `json:"Version"` - Repo string `json:"Repo"` - Author string `json:"Author"` -} - -// BoolStatusResponse 布尔状态响应 -type BoolStatusResponse struct { - Enabled bool `json:"enabled"` -} - -// SizeLimitResponse 大小限制响应 -type SizeLimitResponse struct { - MaxResponseBodySize int `json:"MaxResponseBodySize"` -} - -// WhitelistStatusResponse 白名单状态响应 -type WhitelistStatusResponse struct { - Whitelist bool `json:"Whitelist"` -} - -// BlacklistStatusResponse 黑名单状态响应 -type BlacklistStatusResponse struct { - Blacklist bool `json:"Blacklist"` -} - -// CorsStatusResponse CORS 状态响应 -type CorsStatusResponse struct { - Cors string `json:"Cors"` -} - -// RateLimitStatusResponse 速率限制状态响应 -type RateLimitStatusResponse struct { - RateLimit bool `json:"RateLimit"` -} - -// RateLimitLimitResponse 速率限制值响应 -type RateLimitLimitResponse struct { - RatePerMinute int `json:"RatePerMinute"` -} - -// SmartGitStatusResponse SmartGit 状态响应 -type SmartGitStatusResponse struct { - Enabled bool `json:"enabled"` -} - -// ShellNestStatusResponse Shell Nest 状态响应 -type ShellNestStatusResponse struct { - Enabled bool `json:"enabled"` -} - -// OCIDockerResponse OCI/Docker 代理状态响应 -type OCIDockerResponse struct { - Enabled bool `json:"enabled"` - Target string `json:"target,omitempty"` -} - -// 预定义的固定响应实例,避免重复分配 -var ( - // baseHealthcheckResponse 基础健康检查响应(固定部分) - baseHealthcheckResponse = HealthcheckResponse{ - Status: "OK", - Repo: "WJQSERVER-STUDIO/GHProxy", - Author: "WJQSERVER-STUDIO", - } - - // baseVersionResponse 基础版本响应(固定部分) - baseVersionResponse = VersionResponse{ - Repo: "WJQSERVER-STUDIO/GHProxy", - Author: "WJQSERVER-STUDIO", - } -) diff --git a/go.mod b/go.mod index 04c8a57..d43cb00 100644 --- a/go.mod +++ b/go.mod @@ -1,30 +1,27 @@ module ghproxy -go 1.26 +go 1.25.1 require ( - github.com/BurntSushi/toml v1.6.0 - github.com/WJQSERVER-STUDIO/httpc v0.9.0 - golang.org/x/net v0.53.0 - golang.org/x/time v0.15.0 + github.com/BurntSushi/toml v1.5.0 + github.com/WJQSERVER-STUDIO/httpc v0.8.2 + golang.org/x/net v0.44.0 + golang.org/x/time v0.13.0 ) require ( + github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2 github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 - github.com/WJQSERVER/wanf v0.0.8 + github.com/WJQSERVER/wanf v0.0.0-20250810023226-e51d9d0737ee github.com/fenthope/bauth v0.0.1 github.com/fenthope/ikumi v0.0.2 github.com/fenthope/ipfilter v0.0.1 - github.com/fenthope/reco v0.0.5 + github.com/fenthope/reco v0.0.4 github.com/fenthope/record v0.0.4 - github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 + github.com/go-json-experiment/json v0.0.0-20250813233538-9b1f9ea2e11b github.com/hashicorp/golang-lru/v2 v2.0.7 - github.com/infinite-iroha/touka v0.5.1-0.20260409232140-271e54eb4d44 + github.com/infinite-iroha/touka v0.3.7 github.com/wjqserver/modembed v0.0.1 ) -require ( - github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.3 // indirect - github.com/valyala/bytebufferpool v1.0.0 // indirect - golang.org/x/text v0.36.0 // indirect -) +require github.com/valyala/bytebufferpool v1.0.0 // indirect diff --git a/go.sum b/go.sum index 9d10696..97337f6 100644 --- a/go.sum +++ b/go.sum @@ -1,36 +1,34 @@ -github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= -github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.3 h1:Hc1O6D50U3URkdSzfQ/SgeUU750wUBCYhefdvAbE2Ck= -github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.3/go.mod h1:nFQzepAwwdj5Hp5U+X19l4FVvsaOSBTW41BzfI/CkMA= +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2 h1:AiIHXP21LpK7pFfqUlUstgQEWzjbekZgxOuvVwiMfyM= +github.com/WJQSERVER-STUDIO/go-utils/iox v0.0.2/go.mod h1:mCLqYU32bTmEE6dpj37MKKiZgz70Jh/xyK9vVbq6pok= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 h1:8bBkKk6E2Zr+I5szL7gyc5f0DK8N9agIJCpM1Cqw2NE= github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2/go.mod h1:yPX8xuZH+py7eLJwOYj3VVI/4/Yuy5+x8Mhq8qezcPg= -github.com/WJQSERVER-STUDIO/httpc v0.9.0 h1:MpXcQQqukrSLHH/2tTfnXrhqD6nEDHB/gbzehXaS8o4= -github.com/WJQSERVER-STUDIO/httpc v0.9.0/go.mod h1:filzryrl4eAtFVyl4oVHcJqx1SpNFbrCn+ddQPLlCSg= -github.com/WJQSERVER/wanf v0.0.8 h1:1Ri9d7nKhu22hGxP8O9B9rXnYym6DYGKgi6WRVx3VF8= -github.com/WJQSERVER/wanf v0.0.8/go.mod h1:R0Zw/1skEMVlQ9m5atbkmanlW+9h2bkdq7+wbPY+F/8= +github.com/WJQSERVER-STUDIO/httpc v0.8.2 h1:PFPLodV0QAfGEP6915J57vIqoKu9cGuuiXG/7C9TNUk= +github.com/WJQSERVER-STUDIO/httpc v0.8.2/go.mod h1:8WhHVRO+olDFBSvL5PC/bdMkb6U3vRdPJ4p4pnguV5Y= +github.com/WJQSERVER/wanf v0.0.0-20250810023226-e51d9d0737ee h1:tJ31DNBn6UhWkk8fiikAQWqULODM+yBcGAEar1tzdZc= +github.com/WJQSERVER/wanf v0.0.0-20250810023226-e51d9d0737ee/go.mod h1:q2Pyg+G+s1acMWxrbI4CwS/Yk76/BzLREEdZ8iFwUNE= github.com/fenthope/bauth v0.0.1 h1:+4UIQshGx3mYD4L3f2S4MLZOi5PWU7fU5GK3wsZvwzE= github.com/fenthope/bauth v0.0.1/go.mod h1:1fveTpgfR1p+WXQ8MXm9BfBCeNYi55j23jxCOGOvBSA= github.com/fenthope/ikumi v0.0.2 h1:5oaSTf/Msp7M2O3o/X20omKWEQbFhX4KV0CVF21oCdk= github.com/fenthope/ikumi v0.0.2/go.mod h1:IYbxzOGndZv/yRrbVMyV6dxh06X2wXCbfxrTRM1IruU= github.com/fenthope/ipfilter v0.0.1 h1:HrYAyixCMvsDAz36GRyFfyCNtrgYwzrhMcY0XV7fGcM= github.com/fenthope/ipfilter v0.0.1/go.mod h1:QfY0GrpG0D82HROgdH4c9eog4js42ghLIfl/iM4MvvY= -github.com/fenthope/reco v0.0.5 h1:Z/bOunFf4LSgYP/IxG9fe2pTrIq7bPsDflflbNR5Agw= -github.com/fenthope/reco v0.0.5/go.mod h1:nd5gMkuJHN2+2Iwwt3xy+HSqRaROauIjHNkmQWRsHyM= +github.com/fenthope/reco v0.0.4 h1:yo2g3aWwdoMpaZWZX4SdZOW7mCK82RQIU/YI8ZUQThM= +github.com/fenthope/reco v0.0.4/go.mod h1:eMyS8HpdMVdJ/2WJt6Cvt8P1EH9Igzj5lSJrgc+0jeg= github.com/fenthope/record v0.0.4 h1:/1JHNCxiXGLL/qCh4LEGaAvhj4CcKsb6siTxjLmjdO4= github.com/fenthope/record v0.0.4/go.mod h1:G0a6KCiCDyX2SsC3nfzSN651fJKxH482AyJvzlnvAJU= -github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao= -github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg= +github.com/go-json-experiment/json v0.0.0-20250813233538-9b1f9ea2e11b h1:6Q4zRHXS/YLOl9Ng1b1OOOBWMidAQZR3Gel0UKPC/KU= +github.com/go-json-experiment/json v0.0.0-20250813233538-9b1f9ea2e11b/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/infinite-iroha/touka v0.5.1-0.20260409232140-271e54eb4d44 h1:VcFNhePZe8qhc9M3Qd0HzV6LjU3QCXxWjQokgFlp3TU= -github.com/infinite-iroha/touka v0.5.1-0.20260409232140-271e54eb4d44/go.mod h1:6s1oUso8IQp9MbJ+hDvxx8AodbOF7YMel2DnW/x0qrg= +github.com/infinite-iroha/touka v0.3.7 h1:bIIZW5Weh7lVpyOWh4FmyR9UOfb5FOt+cR9yQ30FJLA= +github.com/infinite-iroha/touka v0.3.7/go.mod h1:uwkF1gTrNEgQ4P/Gwtk6WLbERehq3lzB8x1FMedyrfE= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/wjqserver/modembed v0.0.1 h1:8ZDz7t9M5DLrUFlYgBUUmrMzxWsZPmHvOazkr/T2jEs= github.com/wjqserver/modembed v0.0.1/go.mod h1:sYbQJMAjSBsdYQrUsuHY380XXE1CuRh8g9yyCztTXOQ= -golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= -golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= -golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= -golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= +golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I= +golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/time v0.13.0 h1:eUlYslOIt32DgYD6utsuUeHs4d7AsEYLuIAdg7FlYgI= +golang.org/x/time v0.13.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= diff --git a/main.go b/main.go index e978552..5f5b3ed 100644 --- a/main.go +++ b/main.go @@ -517,7 +517,7 @@ func main() { defer logger.Close() addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port) - err := r.Run(touka.WithAddr(addr), touka.WithGracefulShutdownDefault()) + err := r.RunShutdown(addr) if err != nil { logger.Errorf("Server Run Error: %v", err) fmt.Printf("Server Run Error: %v\n", err) diff --git a/proxy/dial.go b/proxy/dial.go index 2f9393f..ddf5028 100644 --- a/proxy/dial.go +++ b/proxy/dial.go @@ -72,7 +72,7 @@ func newProxyDial(proxyUrls string) proxy.Dialer { var proxyDialer proxy.Dialer = proxy.Direct // 初始为直接连接,不使用代理 // 支持多个代理 URL(以逗号分隔) - for proxyUrl := range strings.SplitSeq(proxyUrls, ",") { + for _, proxyUrl := range strings.Split(proxyUrls, ",") { proxyUrl = strings.TrimSpace(proxyUrl) // 去除首尾空格 if proxyUrl == "" { // 跳过空的代理 URL continue diff --git a/proxy/docker.go b/proxy/docker.go index 9c4f525..fb0c309 100644 --- a/proxy/docker.go +++ b/proxy/docker.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "io" "net/http" "net/url" "strconv" @@ -13,6 +12,7 @@ import ( "ghproxy/config" "ghproxy/weakcache" + "github.com/WJQSERVER-STUDIO/go-utils/iox" "github.com/WJQSERVER-STUDIO/go-utils/limitreader" "github.com/go-json-experiment/json" "github.com/infinite-iroha/touka" @@ -363,7 +363,7 @@ func GhcrRequest(ctx context.Context, c *touka.Context, u string, image *imageIn // 如果最终响应是 404, 则读取响应体并返回自定义错误页面 if resp.StatusCode == 404 { defer resp.Body.Close() // 使用defer确保在函数返回前关闭响应体 - bodyBytes, err := io.ReadAll(resp.Body) + bodyBytes, err := iox.ReadAll(resp.Body) if err != nil { c.Warnf("Failed to read upstream 404 response body: %v", err) } else { @@ -481,7 +481,7 @@ func ChallengeReq(target string, image *imageInfo, ctx context.Context, c *touka defer authResp.Body.Close() // 确保响应体关闭 // 读取认证响应体 - bodyBytes, err := io.ReadAll(authResp.Body) + bodyBytes, err := iox.ReadAll(authResp.Body) if err != nil { c.Errorf("Failed to read auth response body: %v", err) return diff --git a/proxy/error.go b/proxy/error.go index 366aada..79f38ab 100644 --- a/proxy/error.go +++ b/proxy/error.go @@ -289,7 +289,7 @@ func getParsedTemplate() (*template.Template, error) { } // htmlTemplateRender 修改为使用缓存的模板。 -func htmlTemplateRender(data any) ([]byte, error) { +func htmlTemplateRender(data interface{}) ([]byte, error) { tmpl, err := getParsedTemplate() if err != nil { return nil, fmt.Errorf("failed to get parsed template: %w", err)