```
feat: 添加TCP代理服务器功能 新增TCP代理服务器支持,允许在指定端口监听TCP请求并转发到目标服务器。 - 在README.md中添加TCP代理服务器特性说明 - 添加TCP代理配置文件说明(include/tcp_*.json) - 详细文档化TCP代理配置选项和使用示例 - 在changes.md中更新相关变更记录 - 实现从include目录加载TCP代理配置的功能(gohttp.go) - 支持tcp_*.json文件命名约定的配置加载 ```
This commit is contained in:
parent
5022da4885
commit
43c1d63449
38
README.md
38
README.md
|
|
@ -8,6 +8,7 @@
|
|||
- 静态文件服务
|
||||
- 反向代理(Proxy)
|
||||
- 路径重写(Rewrite)
|
||||
- TCP代理服务器
|
||||
- 健康检查
|
||||
- 访问控制(IP白名单/黑名单)
|
||||
- JWT认证
|
||||
|
|
@ -34,6 +35,7 @@ make build
|
|||
### 配置
|
||||
1. 主配置文件 (config.json)
|
||||
2. 域名配置文件 (include/*.json)
|
||||
3. TCP代理配置文件 (include/tcp_*.json)
|
||||
|
||||
### 配置示例
|
||||
```json
|
||||
|
|
@ -131,6 +133,42 @@ make build
|
|||
- `timeout`: 检查超时时间
|
||||
- `retries`: 失败重试次数
|
||||
|
||||
### TCP代理配置
|
||||
TCP代理支持在指定端口监听TCP请求并转发到指定目标服务器。
|
||||
|
||||
#### 在主配置文件中配置
|
||||
```json
|
||||
{
|
||||
"tcp_proxys": [
|
||||
{
|
||||
"name": "mysql-proxy",
|
||||
"listen": "0.0.0.0:3307",
|
||||
"target": "192.168.1.100:3306",
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 在include目录中配置
|
||||
TCP代理配置也可以从include目录加载,使用 `tcp_*.json` 文件命名约定:
|
||||
|
||||
**include/tcp_mysql.json:**
|
||||
```json
|
||||
{
|
||||
"name": "mysql-proxy",
|
||||
"listen": "0.0.0.0:3307",
|
||||
"target": "192.168.1.100:3306",
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
|
||||
**TCP代理配置项:**
|
||||
- `name`: 代理名称(唯一标识)
|
||||
- `listen`: 监听地址,格式如 `0.0.0.0:3307`
|
||||
- `target`: 目标服务器地址,格式如 `192.168.1.100:3306`
|
||||
- `enabled`: 是否启用
|
||||
|
||||
## 指令系统
|
||||
|
||||
指令系统采用类似Nginx的指令系统,格式为:
|
||||
|
|
|
|||
26
changes.md
26
changes.md
|
|
@ -179,7 +179,31 @@ type TcpProxyConfig struct {
|
|||
}
|
||||
```
|
||||
|
||||
### 6.5 服务器管理 (server/manager.go)
|
||||
### 6.5 从include目录加载TCP代理配置
|
||||
|
||||
TCP代理配置也可以从include目录中加载,使用 `tcp_*.json` 文件命名约定:
|
||||
|
||||
**include目录结构:**
|
||||
```
|
||||
./include/
|
||||
├── servers/
|
||||
│ ├── web.json
|
||||
│ └── api.json
|
||||
├── tcp_mysql.json # TCP代理配置
|
||||
└── tcp_redis.json # TCP代理配置
|
||||
```
|
||||
|
||||
**include/tcp_mysql.json 示例:**
|
||||
```json
|
||||
{
|
||||
"name": "mysql-proxy",
|
||||
"listen": "0.0.0.0:3307",
|
||||
"target": "192.168.1.100:3306",
|
||||
"enabled": true
|
||||
}
|
||||
```
|
||||
|
||||
### 6.6 服务器管理 (server/manager.go)
|
||||
|
||||
新增TCP代理服务器管理功能:
|
||||
- `TcpProxyManager`:TCP代理处理器映射
|
||||
|
|
|
|||
20
gohttp.go
20
gohttp.go
|
|
@ -148,6 +148,26 @@ func LoadConfig() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载TCP代理配置 from include directory (tcp_*.json files)
|
||||
tcpConfigs, err := filepath.Glob(model.Config.IncludDir + "/tcp_*.json")
|
||||
if err == nil {
|
||||
for _, config := range tcpConfigs {
|
||||
content, err := os.ReadFile(config)
|
||||
if err == nil {
|
||||
decoder := json.NewDecoder(strings.NewReader(string(content)))
|
||||
for decoder.More() {
|
||||
tcpProxy := model.TcpProxyConfig{}
|
||||
err = decoder.Decode(&tcpProxy)
|
||||
if err == nil {
|
||||
model.Config.TcpProxys = append(model.Config.TcpProxys, &tcpProxy)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历配置中的所有服务器,规范化每个服务器配置中的路径
|
||||
|
|
|
|||
Loading…
Reference in New Issue