feat(proxy): add modify proxy API endpoint and functionality

Implement proxy modification feature including:
- New modifyFrpcProxy function in config.go
- New ModifyProxyHandler in frpcProxyAct.go
- New API endpoint in router.go
- Updated API documentation in docs/api.md
This commit is contained in:
2026-03-31 23:04:43 +08:00
parent f4d742de04
commit 0e578c422f
5 changed files with 215 additions and 0 deletions
+33
View File
@@ -294,6 +294,39 @@ func removeFrpcProxy(configContent string, proxyName string) (string, error) {
return result, nil
}
func modifyFrpcProxy(configContent string, info FrpcProxyInfo) (string, error) {
config, err := decodeFrpcConfig(configContent)
if err != nil {
return "", fmt.Errorf("failed to parse config: %w", err)
}
var found bool
for i, proxy := range config.Proxies {
if name, ok := proxy["name"].(string); ok && name == info.Name {
config.Proxies[i] = map[string]interface{}{
"name": info.Name,
"type": info.Type,
"localIP": info.LocalIP,
"localPort": info.LocalPort,
"remotePort": info.RemotePort,
}
found = true
break
}
}
if !found {
return "", fmt.Errorf("proxy %s not found", info.Name)
}
result, err := encodeFrpcConfig(config)
if err != nil {
return "", fmt.Errorf("failed to write config: %w", err)
}
return result, nil
}
func getKeyText(configPath, key, section string) (value string, err error) {
configContent, err := os.ReadFile(configPath)
if err != nil {