From b06c44bebff384b738607bcb6840d56081059733 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 12 Aug 2023 17:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86api.yaml=E4=BF=AE=E6=94=B9=E4=B8=BAapi?= =?UTF-8?q?=5Fadmin.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/configs/.gitignore | 1 + build/configs/api.template.yaml | 4 - build/configs/api_admin.template.yaml | 3 + internal/configs/api_config.go | 76 +++++++++++++++---- internal/nodes/admin_node.go | 2 +- internal/rpc/rpc_client.go | 2 +- internal/setup/utils.go | 9 +-- internal/tasks/task_sync_api_nodes.go | 8 +- internal/utils/apinodeutils/upgrader.go | 2 +- internal/web/actions/actionutils/utils.go | 4 +- .../actions/default/nodes/nodeutils/utils.go | 22 ++---- .../actions/default/recover/updateHosts.go | 30 +++----- .../actions/default/recover/validateApi.go | 11 +-- .../default/settings/api/node/upgradeCheck.go | 2 +- .../default/settings/transfer/updateHosts.go | 2 +- .../default/settings/transfer/validateAPI.go | 2 +- .../actions/default/setup/confirm/index.go | 10 +-- internal/web/actions/default/setup/install.go | 26 ++----- .../web/actions/default/setup/validateApi.go | 11 +-- 19 files changed, 113 insertions(+), 114 deletions(-) delete mode 100644 build/configs/api.template.yaml create mode 100644 build/configs/api_admin.template.yaml diff --git a/build/configs/.gitignore b/build/configs/.gitignore index 3c99e472..a1ecc9d3 100644 --- a/build/configs/.gitignore +++ b/build/configs/.gitignore @@ -1,4 +1,5 @@ api.yaml +api_admin.yaml server.yaml api_db.yaml *.pem diff --git a/build/configs/api.template.yaml b/build/configs/api.template.yaml deleted file mode 100644 index 31c411dd..00000000 --- a/build/configs/api.template.yaml +++ /dev/null @@ -1,4 +0,0 @@ -rpc: - endpoints: [ "http://127.0.0.1:8003" ] -nodeId: "" -secret: "" \ No newline at end of file diff --git a/build/configs/api_admin.template.yaml b/build/configs/api_admin.template.yaml new file mode 100644 index 00000000..9e453e9e --- /dev/null +++ b/build/configs/api_admin.template.yaml @@ -0,0 +1,3 @@ +rpc.endpoints: [ "http://127.0.0.1:8003" ] +nodeId: "" +secret: "" \ No newline at end of file diff --git a/internal/configs/api_config.go b/internal/configs/api_config.go index 0af3ace8..2783d841 100644 --- a/internal/configs/api_config.go +++ b/internal/configs/api_config.go @@ -1,6 +1,7 @@ package configs import ( + "errors" teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/iwind/TeaGo/Tea" "gopkg.in/yaml.v3" @@ -8,12 +9,19 @@ import ( "path/filepath" ) +const ConfigFileName = "api_admin.yaml" +const oldConfigFileName = "api.yaml" + // APIConfig API配置 type APIConfig struct { - RPC struct { + OldRPC struct { Endpoints []string `yaml:"endpoints"` DisableUpdate bool `yaml:"disableUpdate"` } `yaml:"rpc"` + + RPCEndpoints []string `yaml:"rpc.endpoints" json:"rpc.endpoints"` + RPCDisableUpdate bool `yaml:"rpc.disableUpdate" json:"rpc.disableUpdate"` + NodeId string `yaml:"nodeId"` Secret string `yaml:"secret"` } @@ -21,21 +29,22 @@ type APIConfig struct { // LoadAPIConfig 加载API配置 func LoadAPIConfig() (*APIConfig, error) { // 候选文件 - var localFile = Tea.ConfigFile("api.yaml") + var realFile = Tea.ConfigFile(ConfigFileName) + var oldRealFile = Tea.ConfigFile(oldConfigFileName) var isFromLocal = false - var paths = []string{localFile} + var paths = []string{realFile, oldRealFile} homeDir, homeErr := os.UserHomeDir() if homeErr == nil { - paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/api.yaml") + paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/"+ConfigFileName) } - paths = append(paths, "/etc/"+teaconst.ProcessName+"/api.yaml") + paths = append(paths, "/etc/"+teaconst.ProcessName+"/"+ConfigFileName) var data []byte var err error for _, path := range paths { data, err = os.ReadFile(path) if err == nil { - if path == localFile { + if path == realFile || path == oldRealFile { isFromLocal = true } break @@ -51,9 +60,14 @@ func LoadAPIConfig() (*APIConfig, error) { return nil, err } + err = config.Init() + if err != nil { + return nil, errors.New("init error: " + err.Error()) + } + if !isFromLocal { // 恢复文件 - _ = os.WriteFile(localFile, data, 0666) + _ = os.WriteFile(realFile, data, 0666) } return config, nil @@ -61,9 +75,9 @@ func LoadAPIConfig() (*APIConfig, error) { // ResetAPIConfig 重置配置 func ResetAPIConfig() error { - var filename = "api.yaml" + var filename = ConfigFileName - // 重置 configs/api.yaml + // 重置 configs/api_admin.yaml { var configFile = Tea.ConfigFile(filename) stat, err := os.Stat(configFile) @@ -75,7 +89,7 @@ func ResetAPIConfig() error { } } - // 重置 ~/.edge-admin/api.yaml + // 重置 ~/.edge-admin/api_admin.yaml homeDir, homeErr := os.UserHomeDir() if homeErr == nil { var configFile = homeDir + "/." + teaconst.ProcessName + "/" + filename @@ -88,7 +102,7 @@ func ResetAPIConfig() error { } } - // 重置 /etc/edge-admin/api.yaml + // 重置 /etc/edge-admin/api_admin.yaml { var configFile = "/etc/" + teaconst.ProcessName + "/" + filename stat, err := os.Stat(configFile) @@ -103,6 +117,22 @@ func ResetAPIConfig() error { return nil } +func IsNewInstalled() bool { + homeDir, err := os.UserHomeDir() + if err != nil { + return false + } + + for _, filename := range []string{ConfigFileName, oldConfigFileName} { + _, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/" + filename) + if err == nil { + return false + } + } + + return true +} + // WriteFile 写入API配置 func (this *APIConfig) WriteFile(path string) error { data, err := yaml.Marshal(this) @@ -159,11 +189,27 @@ func (this *APIConfig) WriteFile(path string) error { // Clone 克隆当前配置 func (this *APIConfig) Clone() *APIConfig { return &APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{}, NodeId: this.NodeId, Secret: this.Secret, } } + +func (this *APIConfig) Init() error { + // compatible with old + if len(this.RPCEndpoints) == 0 && len(this.OldRPC.Endpoints) > 0 { + this.RPCEndpoints = this.OldRPC.Endpoints + this.RPCDisableUpdate = this.OldRPC.DisableUpdate + } + + if len(this.RPCEndpoints) == 0 { + return errors.New("no valid 'rpc.endpoints'") + } + + if len(this.NodeId) == 0 { + return errors.New("'nodeId' required") + } + if len(this.Secret) == 0 { + return errors.New("'secret' required") + } + return nil +} diff --git a/internal/nodes/admin_node.go b/internal/nodes/admin_node.go index e18ac89e..5ef66da7 100644 --- a/internal/nodes/admin_node.go +++ b/internal/nodes/admin_node.go @@ -255,7 +255,7 @@ func (this *AdminNode) addPortsToFirewall() { // 启动API节点 func (this *AdminNode) startAPINode() { - configPath := Tea.Root + "/edge-api/configs/api.yaml" + var configPath = Tea.Root + "/edge-api/configs/api.yaml" _, err := os.Stat(configPath) canStart := false if err == nil { diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 6d5d68f9..22c5313d 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -523,7 +523,7 @@ func (this *RPCClient) init() error { // 重新连接 var conns = []*grpc.ClientConn{} - for _, endpoint := range this.apiConfig.RPC.Endpoints { + for _, endpoint := range this.apiConfig.RPCEndpoints { u, err := url.Parse(endpoint) if err != nil { return fmt.Errorf("parse endpoint failed: %w", err) diff --git a/internal/setup/utils.go b/internal/setup/utils.go index 12b061a6..dbc27eec 100644 --- a/internal/setup/utils.go +++ b/internal/setup/utils.go @@ -2,8 +2,6 @@ package setup import ( "github.com/TeaOSLab/EdgeAdmin/internal/configs" - teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" - "os" ) var isConfigured bool @@ -21,10 +19,5 @@ func IsConfigured() bool { // IsNewInstalled IsNew 检查是否新安装 func IsNewInstalled() bool { - homeDir, err := os.UserHomeDir() - if err != nil { - return false - } - _, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/api.yaml") - return err != nil + return configs.IsNewInstalled() } diff --git a/internal/tasks/task_sync_api_nodes.go b/internal/tasks/task_sync_api_nodes.go index efc07f63..4d588055 100644 --- a/internal/tasks/task_sync_api_nodes.go +++ b/internal/tasks/task_sync_api_nodes.go @@ -65,7 +65,7 @@ func (this *SyncAPINodesTask) Loop() error { } // 是否禁止自动升级 - if config.RPC.DisableUpdate { + if config.RPCDisableUpdate { return nil } @@ -88,7 +88,7 @@ func (this *SyncAPINodesTask) Loop() error { } // 和现有的对比 - if this.isSame(newEndpoints, config.RPC.Endpoints) { + if this.isSame(newEndpoints, config.RPCEndpoints) { return nil } @@ -99,14 +99,14 @@ func (this *SyncAPINodesTask) Loop() error { } // 修改RPC对象配置 - config.RPC.Endpoints = newEndpoints + config.RPCEndpoints = newEndpoints err = rpcClient.UpdateConfig(config) if err != nil { return err } // 保存到文件 - err = config.WriteFile(Tea.ConfigFile("api.yaml")) + err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName)) if err != nil { return err } diff --git a/internal/utils/apinodeutils/upgrader.go b/internal/utils/apinodeutils/upgrader.go index 730f1802..c41c41aa 100644 --- a/internal/utils/apinodeutils/upgrader.go +++ b/internal/utils/apinodeutils/upgrader.go @@ -57,7 +57,7 @@ func (this *Upgrader) Upgrade() error { return err } var newAPIConfig = apiConfig.Clone() - newAPIConfig.RPC.Endpoints = apiNode.AccessAddrs + newAPIConfig.RPCEndpoints = apiNode.AccessAddrs rpcClient, err := rpc.NewRPCClient(newAPIConfig, false) if err != nil { diff --git a/internal/web/actions/actionutils/utils.go b/internal/web/actions/actionutils/utils.go index f265df2d..cfa0a63e 100644 --- a/internal/web/actions/actionutils/utils.go +++ b/internal/web/actions/actionutils/utils.go @@ -155,11 +155,11 @@ func parseAPIErr(action actions.ActionWrapper, err error) (apiNodeIsStarting boo var apiEndpoints = []string{} apiConfig, apiConfigErr := configs.LoadAPIConfig() if apiConfigErr == nil && apiConfig != nil { - apiEndpoints = append(apiEndpoints, apiConfig.RPC.Endpoints...) + apiEndpoints = append(apiEndpoints, apiConfig.RPCEndpoints...) } var isRPCConnError bool - _, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile("api.yaml")) + _, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile(configs.ConfigFileName)) if isRPCConnError { // API节点是否正在启动 var sock = gosock.NewTmpSock("edge-api") diff --git a/internal/web/actions/default/nodes/nodeutils/utils.go b/internal/web/actions/default/nodes/nodeutils/utils.go index ab78e139..c6b3a3aa 100644 --- a/internal/web/actions/default/nodes/nodeutils/utils.go +++ b/internal/web/actions/default/nodes/nodeutils/utils.go @@ -101,14 +101,9 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg apiNode := apiNodeResp.ApiNode apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: apiNode.AccessAddrs, - }, - NodeId: apiNode.UniqueId, - Secret: apiNode.Secret, + RPCEndpoints: apiNode.AccessAddrs, + NodeId: apiNode.UniqueId, + Secret: apiNode.Secret, }, false) if err != nil { locker.Lock() @@ -282,14 +277,9 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg apiNode := apiNodeResp.ApiNode apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: apiNode.AccessAddrs, - }, - NodeId: apiNode.UniqueId, - Secret: apiNode.Secret, + RPCEndpoints: apiNode.AccessAddrs, + NodeId: apiNode.UniqueId, + Secret: apiNode.Secret, }, false) if err != nil { locker.Lock() diff --git a/internal/web/actions/default/recover/updateHosts.go b/internal/web/actions/default/recover/updateHosts.go index ca33c0e7..9ea8967a 100644 --- a/internal/web/actions/default/recover/updateHosts.go +++ b/internal/web/actions/default/recover/updateHosts.go @@ -35,14 +35,9 @@ func (this *UpdateHostsAction) RunPost(params struct { } client, err := rpc.NewRPCClient(&configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}, - }, - NodeId: params.NodeId, - Secret: params.NodeSecret, + RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}, + NodeId: params.NodeId, + Secret: params.NodeSecret, }, false) if err != nil { this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error()) @@ -165,23 +160,18 @@ func (this *UpdateHostsAction) RunPost(params struct { } } - // 修改api.yaml + // 修改api_admin.yaml var apiConfig = &configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: endpoints, - }, - NodeId: adminAPIToken.NodeId, - Secret: adminAPIToken.Secret, + RPCEndpoints: endpoints, + NodeId: adminAPIToken.NodeId, + Secret: adminAPIToken.Secret, } - err = apiConfig.WriteFile(Tea.Root + "/configs/api.yaml") + err = apiConfig.WriteFile(Tea.Root + "/configs/" + configs.ConfigFileName) if err != nil { - this.Fail("保存configs/api.yaml失败:" + err.Error()) + this.Fail("保存configs/" + configs.ConfigFileName + "失败:" + err.Error()) } - // 加载api.yaml + // 加载api_admin.yaml rpcClient, err := rpc.SharedRPC() if err != nil { this.Fail("初始化RPC失败:" + err.Error()) diff --git a/internal/web/actions/default/recover/validateApi.go b/internal/web/actions/default/recover/validateApi.go index ae1973f8..bf1ae912 100644 --- a/internal/web/actions/default/recover/validateApi.go +++ b/internal/web/actions/default/recover/validateApi.go @@ -42,14 +42,9 @@ func (this *ValidateApiAction) RunPost(params struct { Field("nodeSecret", params.NodeSecret). Require("请输入节点secret") client, err := rpc.NewRPCClient(&configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}, - }, - NodeId: params.NodeId, - Secret: params.NodeSecret, + RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}, + NodeId: params.NodeId, + Secret: params.NodeSecret, }, false) if err != nil { this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error()) diff --git a/internal/web/actions/default/settings/api/node/upgradeCheck.go b/internal/web/actions/default/settings/api/node/upgradeCheck.go index 0b06b1b0..4fe4bfe1 100644 --- a/internal/web/actions/default/settings/api/node/upgradeCheck.go +++ b/internal/web/actions/default/settings/api/node/upgradeCheck.go @@ -43,7 +43,7 @@ func (this *UpgradeCheckAction) RunPost(params struct { } var newAPIConfig = apiConfig.Clone() - newAPIConfig.RPC.Endpoints = node.AccessAddrs + newAPIConfig.RPCEndpoints = node.AccessAddrs rpcClient, err := rpc.NewRPCClient(newAPIConfig, false) if err != nil { this.Success() diff --git a/internal/web/actions/default/settings/transfer/updateHosts.go b/internal/web/actions/default/settings/transfer/updateHosts.go index cf4d7ce7..8e748f0a 100644 --- a/internal/web/actions/default/settings/transfer/updateHosts.go +++ b/internal/web/actions/default/settings/transfer/updateHosts.go @@ -36,7 +36,7 @@ func (this *UpdateHostsAction) RunPost(params struct { this.Fail("加载当前平台的API配置失败:" + err.Error()) } var apiURL = params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port - config.RPC.Endpoints = []string{apiURL} + config.RPCEndpoints = []string{apiURL} client, err := rpc.NewRPCClient(config, false) if err != nil { this.Fail("检查API节点地址出错:" + err.Error()) diff --git a/internal/web/actions/default/settings/transfer/validateAPI.go b/internal/web/actions/default/settings/transfer/validateAPI.go index e3e2ec67..94ae9737 100644 --- a/internal/web/actions/default/settings/transfer/validateAPI.go +++ b/internal/web/actions/default/settings/transfer/validateAPI.go @@ -43,7 +43,7 @@ func (this *ValidateAPIAction) RunPost(params struct { if err != nil { this.Fail("加载当前平台的API配置失败:" + err.Error()) } - config.RPC.Endpoints = []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port} + config.RPCEndpoints = []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port} client, err := rpc.NewRPCClient(config, false) if err != nil { this.Fail("检查API节点地址出错:" + err.Error()) diff --git a/internal/web/actions/default/setup/confirm/index.go b/internal/web/actions/default/setup/confirm/index.go index af2ced58..58119aba 100644 --- a/internal/web/actions/default/setup/confirm/index.go +++ b/internal/web/actions/default/setup/confirm/index.go @@ -26,7 +26,7 @@ func (this *IndexAction) RunGet(params struct{}) { config, err := configs.LoadAPIConfig() if err == nil { - endpoints = config.RPC.Endpoints + endpoints = config.RPCEndpoints this.Data["nodeId"] = config.NodeId this.Data["secret"] = config.Secret this.Data["canInstall"] = false @@ -78,7 +78,7 @@ func (this *IndexAction) RunPost(params struct { var config = &configs.APIConfig{} config.NodeId = params.NodeId config.Secret = params.Secret - config.RPC.Endpoints = []string{endpoint} + config.RPCEndpoints = []string{endpoint} client, err := rpc.NewRPCClient(config, false) if err != nil { this.Fail("尝试配置RPC发生错误:" + err.Error()) @@ -124,9 +124,9 @@ func (this *IndexAction) RunPost(params struct { } config.NodeId = params.NodeId config.Secret = params.Secret - config.RPC.Endpoints = endpoints - config.RPC.DisableUpdate = true - err = config.WriteFile(Tea.ConfigFile("api.yaml")) + config.RPCEndpoints = endpoints + config.RPCDisableUpdate = true + err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName)) if err != nil { this.Fail("配置保存失败:" + err.Error()) } diff --git a/internal/web/actions/default/setup/install.go b/internal/web/actions/default/setup/install.go index 1d2bad97..f594cc94 100644 --- a/internal/web/actions/default/setup/install.go +++ b/internal/web/actions/default/setup/install.go @@ -231,14 +231,9 @@ func (this *InstallAction) RunPost(params struct { // 写入API节点配置,完成安装 var apiConfig = &configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")}, - }, - NodeId: resultMap.GetString("adminNodeId"), - Secret: resultMap.GetString("adminNodeSecret"), + RPCEndpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")}, + NodeId: resultMap.GetString("adminNodeId"), + Secret: resultMap.GetString("adminNodeSecret"), } // 设置管理员 @@ -285,7 +280,7 @@ func (this *InstallAction) RunPost(params struct { } } - err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml")) + err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName)) if err != nil { this.Fail("保存配置失败,原因:" + err.Error()) } @@ -294,14 +289,9 @@ func (this *InstallAction) RunPost(params struct { } else if mode == "old" { // 构造RPC var apiConfig = &configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")}, - }, - NodeId: apiNodeMap.GetString("oldNodeId"), - Secret: apiNodeMap.GetString("oldNodeSecret"), + RPCEndpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")}, + NodeId: apiNodeMap.GetString("oldNodeId"), + Secret: apiNodeMap.GetString("oldNodeSecret"), } client, err := rpc.NewRPCClient(apiConfig, false) if err != nil { @@ -343,7 +333,7 @@ func (this *InstallAction) RunPost(params struct { } // 写入API节点配置,完成安装 - err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml")) + err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName)) if err != nil { this.Fail("保存配置失败,原因:" + err.Error()) } diff --git a/internal/web/actions/default/setup/validateApi.go b/internal/web/actions/default/setup/validateApi.go index f152b6e1..e6643b46 100644 --- a/internal/web/actions/default/setup/validateApi.go +++ b/internal/web/actions/default/setup/validateApi.go @@ -102,14 +102,9 @@ func (this *ValidateApiAction) RunPost(params struct { Field("oldNodeSecret", params.OldNodeSecret). Require("请输入节点secret") client, err := rpc.NewRPCClient(&configs.APIConfig{ - RPC: struct { - Endpoints []string `yaml:"endpoints"` - DisableUpdate bool `yaml:"disableUpdate"` - }{ - Endpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort}, - }, - NodeId: params.OldNodeId, - Secret: params.OldNodeSecret, + RPCEndpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort}, + NodeId: params.OldNodeId, + Secret: params.OldNodeSecret, }, false) if err != nil { this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())