📦 songquanpeng / go-relay

基于 Go 的 HTTP 中继工具,为你的服务器请求 OpenAI 的 API 提供中继服务,也可用于搭建镜像站,开箱即用. Golang based HTTP relay server.

11 stars 2 forks 👁 11 watching ⚖️ MIT License
📥 Clone https://github.com/songquanpeng/go-relay.git
HTTPS git clone https://github.com/songquanpeng/go-relay.git
SSH git clone git@github.com:songquanpeng/go-relay.git
CLI gh repo clone songquanpeng/go-relay
Loading files...
📄 README.md

中文 | English

Go Relay

✨ 基于 Go 的 HTTP 中继,可用于国内服务器请求无法正常访问的 API,也可以用于搭建镜像网站,开箱即用 ✨

license release release docker pull GoReportCard

功能

  • 开箱即用
  • Token 认证
  • 支持镜像网站
  • 支持 HTTP Basic Auth
  • 支持 IP 白名单

用法

中继模式

服务端

# 初始化配置文件
./go-relay init
# 检查并保存生成的令牌
cat go-relay.yaml
# 启动服务器
./go-relay

或者使用 Docker 进行部署:

docker run -d --restart always --name go-relay -p 6872:6872 -v /home/ubuntu/data/go-relay:/app justsong/go-relay

客户端

进行 HTTP 请求时,将请求 URL 中的主机地址和端口替换为你的中继服务器地址和端口。

然后在请求头中添加以下字段:

  • X-Relay-Token:Go Relay 服务端配置的令牌
  • X-Relay-Host:要请求的目标地址
  • X-Relay-Protocol:请求协议,可选,默认为 https

镜像模式

./go-relay mirror https://www.google.com/

或者使用 Docker 进行部署:

docker run -d --restart always --name go-relay -p 6872:6872 -v /home/ubuntu/data/go-relay:/app justsong/go-relay mirror https://www.google.com/

如果你不想要任何人都能使用你的镜像站,可以在配置文件中指定 usernamepassword,之后在请求时使用 HTTP Basic Auth 进行认证。

流程图

sequenceDiagram
    participant Client
    participant Relay
    participant Server
    
    Client->>Relay: HTTP Request
    Relay->>Server: Forward HTTP Request
    Server->>Relay: HTTP Response
    Relay->>Client: Forward HTTP Response