mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
refactor: cmd update.
This commit is contained in:
parent
60446816a7
commit
16d2faa6a3
@ -26,12 +26,12 @@ type ApiCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
apiConfig api.Config
|
||||
apiConfig *api.Config
|
||||
}
|
||||
|
||||
func NewApiCmd() *ApiCmd {
|
||||
var apiConfig api.Config
|
||||
ret := &ApiCmd{apiConfig: apiConfig}
|
||||
ret := &ApiCmd{apiConfig: &apiConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMAPICfgFileName: &apiConfig.RpcConfig,
|
||||
RedisConfigFileName: &apiConfig.RedisConfig,
|
||||
@ -51,5 +51,5 @@ func (a *ApiCmd) Exec() error {
|
||||
}
|
||||
|
||||
func (a *ApiCmd) preRunE() error {
|
||||
return api.Start(a.ctx, a.Index(), &a.apiConfig)
|
||||
return api.Start(a.ctx, a.Index(), a.apiConfig)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type AuthRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
authConfig auth.Config
|
||||
authConfig *auth.Config
|
||||
}
|
||||
|
||||
func NewAuthRpcCmd() *AuthRpcCmd {
|
||||
var authConfig auth.Config
|
||||
ret := &AuthRpcCmd{authConfig: authConfig}
|
||||
ret := &AuthRpcCmd{authConfig: &authConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCAuthCfgFileName: &authConfig.RpcConfig,
|
||||
RedisConfigFileName: &authConfig.RedisConfig,
|
||||
@ -55,5 +55,5 @@ func (a *AuthRpcCmd) Exec() error {
|
||||
func (a *AuthRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.authConfig.ZookeeperConfig, &a.authConfig.RpcConfig.Prometheus, a.authConfig.RpcConfig.RPC.ListenIP,
|
||||
a.authConfig.RpcConfig.RPC.RegisterIP, a.authConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.authConfig.Share.RpcRegisterName.Auth, &a.authConfig.Share, &a.authConfig, auth.Start)
|
||||
a.Index(), a.authConfig.Share.RpcRegisterName.Auth, &a.authConfig.Share, a.authConfig, auth.Start)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type ConversationRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
conversationConfig conversation.Config
|
||||
conversationConfig *conversation.Config
|
||||
}
|
||||
|
||||
func NewConversationRpcCmd() *ConversationRpcCmd {
|
||||
var conversationConfig conversation.Config
|
||||
ret := &ConversationRpcCmd{conversationConfig: conversationConfig}
|
||||
ret := &ConversationRpcCmd{conversationConfig: &conversationConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCConversationCfgFileName: &conversationConfig.RpcConfig,
|
||||
RedisConfigFileName: &conversationConfig.RedisConfig,
|
||||
@ -57,5 +57,5 @@ func (a *ConversationRpcCmd) Exec() error {
|
||||
func (a *ConversationRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.conversationConfig.ZookeeperConfig, &a.conversationConfig.RpcConfig.Prometheus, a.conversationConfig.RpcConfig.RPC.ListenIP,
|
||||
a.conversationConfig.RpcConfig.RPC.RegisterIP, a.conversationConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.conversationConfig.Share.RpcRegisterName.Auth, &a.conversationConfig.Share, &a.conversationConfig, conversation.Start)
|
||||
a.Index(), a.conversationConfig.Share.RpcRegisterName.Auth, &a.conversationConfig.Share, a.conversationConfig, conversation.Start)
|
||||
}
|
||||
|
||||
@ -26,12 +26,12 @@ type CronTaskCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
cronTaskConfig tools.CronTaskConfig
|
||||
cronTaskConfig *tools.CronTaskConfig
|
||||
}
|
||||
|
||||
func NewCronTaskCmd() *CronTaskCmd {
|
||||
var cronTaskConfig tools.CronTaskConfig
|
||||
ret := &CronTaskCmd{cronTaskConfig: cronTaskConfig}
|
||||
ret := &CronTaskCmd{cronTaskConfig: &cronTaskConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMCronTaskCfgFileName: &cronTaskConfig.CronTask,
|
||||
RedisConfigFileName: &cronTaskConfig.RedisConfig,
|
||||
@ -53,5 +53,5 @@ func (a *CronTaskCmd) Exec() error {
|
||||
}
|
||||
|
||||
func (a *CronTaskCmd) preRunE() error {
|
||||
return tools.Start(a.ctx, &a.cronTaskConfig)
|
||||
return tools.Start(a.ctx, a.cronTaskConfig)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type FriendRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
friendConfig friend.Config
|
||||
friendConfig *friend.Config
|
||||
}
|
||||
|
||||
func NewFriendRpcCmd() *FriendRpcCmd {
|
||||
var friendConfig friend.Config
|
||||
ret := &FriendRpcCmd{friendConfig: friendConfig}
|
||||
ret := &FriendRpcCmd{friendConfig: &friendConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCFriendCfgFileName: &friendConfig.RpcConfig,
|
||||
RedisConfigFileName: &friendConfig.RedisConfig,
|
||||
@ -58,5 +58,5 @@ func (a *FriendRpcCmd) Exec() error {
|
||||
func (a *FriendRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.friendConfig.ZookeeperConfig, &a.friendConfig.RpcConfig.Prometheus, a.friendConfig.RpcConfig.RPC.ListenIP,
|
||||
a.friendConfig.RpcConfig.RPC.RegisterIP, a.friendConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.friendConfig.Share.RpcRegisterName.Auth, &a.friendConfig.Share, &a.friendConfig, friend.Start)
|
||||
a.Index(), a.friendConfig.Share.RpcRegisterName.Auth, &a.friendConfig.Share, a.friendConfig, friend.Start)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type MsgRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
msgConfig msg.Config
|
||||
msgConfig *msg.Config
|
||||
}
|
||||
|
||||
func NewMsgRpcCmd() *MsgRpcCmd {
|
||||
var msgConfig msg.Config
|
||||
ret := &MsgRpcCmd{msgConfig: msgConfig}
|
||||
ret := &MsgRpcCmd{msgConfig: &msgConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCMsgCfgFileName: &msgConfig.RpcConfig,
|
||||
RedisConfigFileName: &msgConfig.RedisConfig,
|
||||
@ -59,5 +59,5 @@ func (a *MsgRpcCmd) Exec() error {
|
||||
func (a *MsgRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.msgConfig.ZookeeperConfig, &a.msgConfig.RpcConfig.Prometheus, a.msgConfig.RpcConfig.RPC.ListenIP,
|
||||
a.msgConfig.RpcConfig.RPC.RegisterIP, a.msgConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.msgConfig.Share.RpcRegisterName.Auth, &a.msgConfig.Share, &a.msgConfig, msg.Start)
|
||||
a.Index(), a.msgConfig.Share.RpcRegisterName.Auth, &a.msgConfig.Share, a.msgConfig, msg.Start)
|
||||
}
|
||||
|
||||
@ -28,12 +28,12 @@ type MsgGatewayCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
msgGatewayConfig msggateway.Config
|
||||
msgGatewayConfig *msggateway.Config
|
||||
}
|
||||
|
||||
func NewMsgGatewayCmd() *MsgGatewayCmd {
|
||||
var msgGatewayConfig msggateway.Config
|
||||
ret := &MsgGatewayCmd{msgGatewayConfig: msgGatewayConfig}
|
||||
ret := &MsgGatewayCmd{msgGatewayConfig: &msgGatewayConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway,
|
||||
ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig,
|
||||
@ -53,5 +53,5 @@ func (m *MsgGatewayCmd) Exec() error {
|
||||
}
|
||||
|
||||
func (m *MsgGatewayCmd) preRunE() error {
|
||||
return msggateway.Start(m.ctx, m.Index(), &m.msgGatewayConfig)
|
||||
return msggateway.Start(m.ctx, m.Index(), m.msgGatewayConfig)
|
||||
}
|
||||
|
||||
@ -26,12 +26,12 @@ type MsgTransferCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
msgTransferConfig msgtransfer.Config
|
||||
msgTransferConfig *msgtransfer.Config
|
||||
}
|
||||
|
||||
func NewMsgTransferCmd() *MsgTransferCmd {
|
||||
var msgTransferConfig msgtransfer.Config
|
||||
ret := &MsgTransferCmd{msgTransferConfig: msgTransferConfig}
|
||||
ret := &MsgTransferCmd{msgTransferConfig: &msgTransferConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMMsgTransferCfgFileName: &msgTransferConfig.MsgTransfer,
|
||||
RedisConfigFileName: &msgTransferConfig.RedisConfig,
|
||||
@ -54,5 +54,5 @@ func (m *MsgTransferCmd) Exec() error {
|
||||
}
|
||||
|
||||
func (m *MsgTransferCmd) preRunE() error {
|
||||
return msgtransfer.Start(m.ctx, m.Index(), &m.msgTransferConfig)
|
||||
return msgtransfer.Start(m.ctx, m.Index(), m.msgTransferConfig)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type PushRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
pushConfig push.Config
|
||||
pushConfig *push.Config
|
||||
}
|
||||
|
||||
func NewPushRpcCmd() *PushRpcCmd {
|
||||
var pushConfig push.Config
|
||||
ret := &PushRpcCmd{pushConfig: pushConfig}
|
||||
ret := &PushRpcCmd{pushConfig: &pushConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMPushCfgFileName: &pushConfig.RpcConfig,
|
||||
RedisConfigFileName: &pushConfig.RedisConfig,
|
||||
@ -59,5 +59,5 @@ func (a *PushRpcCmd) Exec() error {
|
||||
func (a *PushRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.pushConfig.ZookeeperConfig, &a.pushConfig.RpcConfig.Prometheus, a.pushConfig.RpcConfig.RPC.ListenIP,
|
||||
a.pushConfig.RpcConfig.RPC.RegisterIP, a.pushConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.pushConfig.Share.RpcRegisterName.Auth, &a.pushConfig.Share, &a.pushConfig, push.Start)
|
||||
a.Index(), a.pushConfig.Share.RpcRegisterName.Auth, &a.pushConfig.Share, a.pushConfig, push.Start)
|
||||
}
|
||||
|
||||
@ -83,7 +83,6 @@ func NewRootCmd(processName string, opts ...func(*CmdOpts)) *RootCmd {
|
||||
|
||||
func (r *RootCmd) persistentPreRun(cmd *cobra.Command, opts ...func(*CmdOpts)) error {
|
||||
cmdOpts := r.applyOptions(opts...)
|
||||
fmt.Println("config", cmdOpts.configMap)
|
||||
if err := r.initializeConfiguration(cmd, cmdOpts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type ThirdRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
thirdConfig third.Config
|
||||
thirdConfig *third.Config
|
||||
}
|
||||
|
||||
func NewThirdRpcCmd() *ThirdRpcCmd {
|
||||
var thirdConfig third.Config
|
||||
ret := &ThirdRpcCmd{thirdConfig: thirdConfig}
|
||||
ret := &ThirdRpcCmd{thirdConfig: &thirdConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCThirdCfgFileName: &thirdConfig.RpcConfig,
|
||||
RedisConfigFileName: &thirdConfig.RedisConfig,
|
||||
@ -58,5 +58,5 @@ func (a *ThirdRpcCmd) Exec() error {
|
||||
func (a *ThirdRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.thirdConfig.ZookeeperConfig, &a.thirdConfig.RpcConfig.Prometheus, a.thirdConfig.RpcConfig.RPC.ListenIP,
|
||||
a.thirdConfig.RpcConfig.RPC.RegisterIP, a.thirdConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.thirdConfig.Share.RpcRegisterName.Auth, &a.thirdConfig.Share, &a.thirdConfig, third.Start)
|
||||
a.Index(), a.thirdConfig.Share.RpcRegisterName.Auth, &a.thirdConfig.Share, a.thirdConfig, third.Start)
|
||||
}
|
||||
|
||||
@ -27,12 +27,12 @@ type UserRpcCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
userConfig user.Config
|
||||
userConfig *user.Config
|
||||
}
|
||||
|
||||
func NewUserRpcCmd() *UserRpcCmd {
|
||||
var userConfig user.Config
|
||||
ret := &UserRpcCmd{userConfig: userConfig}
|
||||
ret := &UserRpcCmd{userConfig: &userConfig}
|
||||
ret.configMap = map[string]any{
|
||||
OpenIMRPCUserCfgFileName: &userConfig.RpcConfig,
|
||||
RedisConfigFileName: &userConfig.RedisConfig,
|
||||
@ -59,5 +59,5 @@ func (a *UserRpcCmd) Exec() error {
|
||||
func (a *UserRpcCmd) preRunE() error {
|
||||
return startrpc.Start(a.ctx, &a.userConfig.ZookeeperConfig, &a.userConfig.RpcConfig.Prometheus, a.userConfig.RpcConfig.RPC.ListenIP,
|
||||
a.userConfig.RpcConfig.RPC.RegisterIP, a.userConfig.RpcConfig.RPC.Ports,
|
||||
a.Index(), a.userConfig.Share.RpcRegisterName.Auth, &a.userConfig.Share, &a.userConfig, user.Start)
|
||||
a.Index(), a.userConfig.Share.RpcRegisterName.Auth, &a.userConfig.Share, a.userConfig, user.Start)
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/spf13/viper"
|
||||
@ -24,6 +23,5 @@ func LoadConfig(path string, envPrefix string, config any) error {
|
||||
}); err != nil {
|
||||
return errs.WrapMsg(err, "failed to unmarshal config", "path", path, "envPrefix", envPrefix)
|
||||
}
|
||||
fmt.Println("Load config success", "path", path, "envPrefix", envPrefix, "config", config)
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user