fix(proxy): add "oldName" && "newName" paras to fix unable to modify proxy name
This commit is contained in:
+14
-3
@@ -23,6 +23,8 @@ type InstanceInfo struct {
|
||||
|
||||
type FrpcProxyInfo struct {
|
||||
Name string `json:"name"`
|
||||
OldName string `json:"oldName"`
|
||||
NewName string `json:"newName"`
|
||||
Type string `json:"type"`
|
||||
LocalIP string `json:"local_ip"`
|
||||
LocalPort int `json:"local_port"`
|
||||
@@ -349,11 +351,20 @@ func ModifyFrpcProxy(configContent string, info FrpcProxyInfo) (string, error) {
|
||||
return "", fmt.Errorf("failed to parse config: %w", err)
|
||||
}
|
||||
|
||||
searchName := info.OldName
|
||||
if searchName == "" {
|
||||
searchName = info.Name
|
||||
}
|
||||
|
||||
var found bool
|
||||
for i, proxy := range config.Proxies {
|
||||
if name, ok := proxy["name"].(string); ok && name == info.Name {
|
||||
if name, ok := proxy["name"].(string); ok && name == searchName {
|
||||
proxyName := info.NewName
|
||||
if proxyName == "" {
|
||||
proxyName = info.Name
|
||||
}
|
||||
config.Proxies[i] = map[string]interface{}{
|
||||
"name": info.Name,
|
||||
"name": proxyName,
|
||||
"type": info.Type,
|
||||
"localIP": info.LocalIP,
|
||||
"localPort": info.LocalPort,
|
||||
@@ -365,7 +376,7 @@ func ModifyFrpcProxy(configContent string, info FrpcProxyInfo) (string, error) {
|
||||
}
|
||||
|
||||
if !found {
|
||||
return "", fmt.Errorf("proxy %s not found", info.Name)
|
||||
return "", fmt.Errorf("proxy %s not found", searchName)
|
||||
}
|
||||
|
||||
result, err := EncodeFrpcConfig(config)
|
||||
|
||||
Reference in New Issue
Block a user