optimization: change the configuration file from being read globally … (#1935)

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: config file changed to dependency injection.

* fix: replace global config with dependency injection

* fix: replace global config with dependency injection

* fix: import the enough param

* fix: import the enough param

* fix: import the enough param

* fix: fix the component check of path

* fix: fix the kafka of tls is nil problem

* fix: fix the TLS.CACrt is nil error

* fix: fix the valiable shadows problem

* fix: fix the comflect

* optimization: message remove options.

* fix: fix the param pass error

* fix: find error

* fix: find error

* fix: find eror

* fix: find error

* fix: find error

* fix: del the undifined func

* fix: find error

* fix: fix the error

* fix: pass config

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: fix the config

* fix: fix the error

* fix: fix the config pass error

* fix: fix the eror

* fix: fix the error

* fix: fix the error

* fix: fix the error

* fix: find error

* fix: fix the error

* fix: fix the config

* fix: add return err

* fix: fix the err2

* fix: err

* fix: fix the func

* fix: del the chinese comment

* fix: fix the func

* fix: fix the gateway_test logic

* fix: s3

* test

* test

* fix: not found

---------

Co-authored-by: luhaoling <2198702716@qq.com>
Co-authored-by: withchao <993506633@qq.com>
This commit is contained in:
OpenIM-Gordon
2024-03-05 17:53:22 +08:00
committed by GitHub
parent efb8310531
commit 383758782e
114 changed files with 1743 additions and 1802 deletions
+16 -43
View File
@@ -15,13 +15,13 @@
package cmd
import (
"errors"
"log"
"github.com/spf13/cobra"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/tools/errs"
"github.com/openimsdk/open-im-server/v3/internal/msggateway"
v3config "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/spf13/cobra"
)
type MsgGatewayCmd struct {
@@ -30,6 +30,7 @@ type MsgGatewayCmd struct {
func NewMsgGatewayCmd() *MsgGatewayCmd {
ret := &MsgGatewayCmd{NewRootCmd("msgGateway")}
ret.addRunE()
ret.SetRootCmdPt(ret)
return ret
}
@@ -38,67 +39,39 @@ func (m *MsgGatewayCmd) AddWsPortFlag() {
m.Command.Flags().IntP(constant.FlagWsPort, "w", 0, "ws server listen port")
}
func (m *MsgGatewayCmd) getWsPortFlag(cmd *cobra.Command) (int, error) {
func (m *MsgGatewayCmd) getWsPortFlag(cmd *cobra.Command) int {
port, err := cmd.Flags().GetInt(constant.FlagWsPort)
if err != nil {
return 0, errs.Wrap(err, "error getting ws port flag")
log.Println("Error getting ws port flag:", err)
}
if port == 0 {
port, _ = m.PortFromConfig(constant.FlagWsPort)
port = m.PortFromConfig(constant.FlagWsPort)
}
return port, nil
return port
}
func (m *MsgGatewayCmd) addRunE() {
m.Command.RunE = func(cmd *cobra.Command, args []string) error {
wsPort, err := m.getWsPortFlag(cmd)
if err != nil {
return errs.Wrap(err, "failed to get WS port flag")
}
port, err := m.getPortFlag(cmd)
if err != nil {
return err
}
prometheusPort, err := m.getPrometheusPortFlag(cmd)
if err != nil {
return err
}
return msggateway.RunWsAndServer(port, wsPort, prometheusPort)
return msggateway.RunWsAndServer(m.config, m.getPortFlag(cmd), m.getWsPortFlag(cmd), m.getPrometheusPortFlag(cmd))
}
}
func (m *MsgGatewayCmd) Exec() error {
m.addRunE()
return m.Execute()
}
func (m *MsgGatewayCmd) GetPortFromConfig(portType string) (int, error) {
var port int
var exists bool
func (m *MsgGatewayCmd) GetPortFromConfig(portType string) int {
switch portType {
case constant.FlagWsPort:
if len(v3config.Config.LongConnSvr.OpenImWsPort) > 0 {
port = v3config.Config.LongConnSvr.OpenImWsPort[0]
exists = true
}
return m.config.LongConnSvr.OpenImWsPort[0]
case constant.FlagPort:
if len(v3config.Config.LongConnSvr.OpenImMessageGatewayPort) > 0 {
port = v3config.Config.LongConnSvr.OpenImMessageGatewayPort[0]
exists = true
}
return m.config.LongConnSvr.OpenImMessageGatewayPort[0]
case constant.FlagPrometheusPort:
if len(v3config.Config.Prometheus.MessageGatewayPrometheusPort) > 0 {
port = v3config.Config.Prometheus.MessageGatewayPrometheusPort[0]
exists = true
}
}
return m.config.Prometheus.MessageGatewayPrometheusPort[0]
if !exists {
return 0, errs.Wrap(errors.New("port type '%s' not found in configuration"), portType)
default:
return 0
}
return port, nil
}