From 0fe248c2b92f8fbddd2c4b577f54470dfef3ea73 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Tue, 5 Mar 2024 14:55:12 +0800 Subject: [PATCH] fix: fix the func --- pkg/common/cmd/api.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/pkg/common/cmd/api.go b/pkg/common/cmd/api.go index 72de059ed..859508ce3 100644 --- a/pkg/common/cmd/api.go +++ b/pkg/common/cmd/api.go @@ -15,9 +15,6 @@ package cmd import ( - "errors" - "fmt" - "github.com/OpenIMSDK/protocol/constant" "github.com/openimsdk/open-im-server/v3/internal/api" "github.com/spf13/cobra" @@ -38,7 +35,6 @@ func NewApiCmd() *ApiCmd { return ret } -// 原来代码 func (a *ApiCmd) addPreRun() { a.Command.PreRun = func(cmd *cobra.Command, args []string) { a.port = a.getPortFlag(cmd) @@ -52,17 +48,11 @@ func (a *ApiCmd) addRunE() { } } -func (a *ApiCmd) GetPortFromConfig(portType string) (int, error) { +func (a *ApiCmd) GetPortFromConfig(portType string) int { if portType == constant.FlagPort { - if len(a.config.Api.OpenImApiPort) > 0 { - return a.config.Api.OpenImApiPort[0], nil - } - return 0, errors.New("API port configuration is empty or missing") + return a.config.Api.OpenImApiPort[0] } else if portType == constant.FlagPrometheusPort { - if len(a.config.Prometheus.ApiPrometheusPort) > 0 { - return a.config.Prometheus.ApiPrometheusPort[0], nil - } - return 0, errors.New("Prometheus port configuration is empty or missing") + return a.config.Prometheus.ApiPrometheusPort[0] } - return 0, fmt.Errorf("unknown port type: %s", portType) + return 0 }