refactor: cmd update.

pull/2148/head
Gordon 1 year ago
parent 60446816a7
commit 16d2faa6a3

@ -26,12 +26,12 @@ type ApiCmd struct {
*RootCmd *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
apiConfig api.Config apiConfig *api.Config
} }
func NewApiCmd() *ApiCmd { func NewApiCmd() *ApiCmd {
var apiConfig api.Config var apiConfig api.Config
ret := &ApiCmd{apiConfig: apiConfig} ret := &ApiCmd{apiConfig: &apiConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMAPICfgFileName: &apiConfig.RpcConfig, OpenIMAPICfgFileName: &apiConfig.RpcConfig,
RedisConfigFileName: &apiConfig.RedisConfig, RedisConfigFileName: &apiConfig.RedisConfig,
@ -51,5 +51,5 @@ func (a *ApiCmd) Exec() error {
} }
func (a *ApiCmd) preRunE() 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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
authConfig auth.Config authConfig *auth.Config
} }
func NewAuthRpcCmd() *AuthRpcCmd { func NewAuthRpcCmd() *AuthRpcCmd {
var authConfig auth.Config var authConfig auth.Config
ret := &AuthRpcCmd{authConfig: authConfig} ret := &AuthRpcCmd{authConfig: &authConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCAuthCfgFileName: &authConfig.RpcConfig, OpenIMRPCAuthCfgFileName: &authConfig.RpcConfig,
RedisConfigFileName: &authConfig.RedisConfig, RedisConfigFileName: &authConfig.RedisConfig,
@ -55,5 +55,5 @@ func (a *AuthRpcCmd) Exec() error {
func (a *AuthRpcCmd) preRunE() error { func (a *AuthRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.authConfig.ZookeeperConfig, &a.authConfig.RpcConfig.Prometheus, a.authConfig.RpcConfig.RPC.ListenIP, 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.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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
conversationConfig conversation.Config conversationConfig *conversation.Config
} }
func NewConversationRpcCmd() *ConversationRpcCmd { func NewConversationRpcCmd() *ConversationRpcCmd {
var conversationConfig conversation.Config var conversationConfig conversation.Config
ret := &ConversationRpcCmd{conversationConfig: conversationConfig} ret := &ConversationRpcCmd{conversationConfig: &conversationConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCConversationCfgFileName: &conversationConfig.RpcConfig, OpenIMRPCConversationCfgFileName: &conversationConfig.RpcConfig,
RedisConfigFileName: &conversationConfig.RedisConfig, RedisConfigFileName: &conversationConfig.RedisConfig,
@ -57,5 +57,5 @@ func (a *ConversationRpcCmd) Exec() error {
func (a *ConversationRpcCmd) preRunE() error { func (a *ConversationRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.conversationConfig.ZookeeperConfig, &a.conversationConfig.RpcConfig.Prometheus, a.conversationConfig.RpcConfig.RPC.ListenIP, 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.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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
cronTaskConfig tools.CronTaskConfig cronTaskConfig *tools.CronTaskConfig
} }
func NewCronTaskCmd() *CronTaskCmd { func NewCronTaskCmd() *CronTaskCmd {
var cronTaskConfig tools.CronTaskConfig var cronTaskConfig tools.CronTaskConfig
ret := &CronTaskCmd{cronTaskConfig: cronTaskConfig} ret := &CronTaskCmd{cronTaskConfig: &cronTaskConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMCronTaskCfgFileName: &cronTaskConfig.CronTask, OpenIMCronTaskCfgFileName: &cronTaskConfig.CronTask,
RedisConfigFileName: &cronTaskConfig.RedisConfig, RedisConfigFileName: &cronTaskConfig.RedisConfig,
@ -53,5 +53,5 @@ func (a *CronTaskCmd) Exec() error {
} }
func (a *CronTaskCmd) preRunE() 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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
friendConfig friend.Config friendConfig *friend.Config
} }
func NewFriendRpcCmd() *FriendRpcCmd { func NewFriendRpcCmd() *FriendRpcCmd {
var friendConfig friend.Config var friendConfig friend.Config
ret := &FriendRpcCmd{friendConfig: friendConfig} ret := &FriendRpcCmd{friendConfig: &friendConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCFriendCfgFileName: &friendConfig.RpcConfig, OpenIMRPCFriendCfgFileName: &friendConfig.RpcConfig,
RedisConfigFileName: &friendConfig.RedisConfig, RedisConfigFileName: &friendConfig.RedisConfig,
@ -58,5 +58,5 @@ func (a *FriendRpcCmd) Exec() error {
func (a *FriendRpcCmd) preRunE() error { func (a *FriendRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.friendConfig.ZookeeperConfig, &a.friendConfig.RpcConfig.Prometheus, a.friendConfig.RpcConfig.RPC.ListenIP, 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.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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
msgConfig msg.Config msgConfig *msg.Config
} }
func NewMsgRpcCmd() *MsgRpcCmd { func NewMsgRpcCmd() *MsgRpcCmd {
var msgConfig msg.Config var msgConfig msg.Config
ret := &MsgRpcCmd{msgConfig: msgConfig} ret := &MsgRpcCmd{msgConfig: &msgConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCMsgCfgFileName: &msgConfig.RpcConfig, OpenIMRPCMsgCfgFileName: &msgConfig.RpcConfig,
RedisConfigFileName: &msgConfig.RedisConfig, RedisConfigFileName: &msgConfig.RedisConfig,
@ -59,5 +59,5 @@ func (a *MsgRpcCmd) Exec() error {
func (a *MsgRpcCmd) preRunE() error { func (a *MsgRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.msgConfig.ZookeeperConfig, &a.msgConfig.RpcConfig.Prometheus, a.msgConfig.RpcConfig.RPC.ListenIP, 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.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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
msgGatewayConfig msggateway.Config msgGatewayConfig *msggateway.Config
} }
func NewMsgGatewayCmd() *MsgGatewayCmd { func NewMsgGatewayCmd() *MsgGatewayCmd {
var msgGatewayConfig msggateway.Config var msgGatewayConfig msggateway.Config
ret := &MsgGatewayCmd{msgGatewayConfig: msgGatewayConfig} ret := &MsgGatewayCmd{msgGatewayConfig: &msgGatewayConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway, OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway,
ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig, ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig,
@ -53,5 +53,5 @@ func (m *MsgGatewayCmd) Exec() error {
} }
func (m *MsgGatewayCmd) preRunE() 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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
msgTransferConfig msgtransfer.Config msgTransferConfig *msgtransfer.Config
} }
func NewMsgTransferCmd() *MsgTransferCmd { func NewMsgTransferCmd() *MsgTransferCmd {
var msgTransferConfig msgtransfer.Config var msgTransferConfig msgtransfer.Config
ret := &MsgTransferCmd{msgTransferConfig: msgTransferConfig} ret := &MsgTransferCmd{msgTransferConfig: &msgTransferConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMMsgTransferCfgFileName: &msgTransferConfig.MsgTransfer, OpenIMMsgTransferCfgFileName: &msgTransferConfig.MsgTransfer,
RedisConfigFileName: &msgTransferConfig.RedisConfig, RedisConfigFileName: &msgTransferConfig.RedisConfig,
@ -54,5 +54,5 @@ func (m *MsgTransferCmd) Exec() error {
} }
func (m *MsgTransferCmd) preRunE() 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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
pushConfig push.Config pushConfig *push.Config
} }
func NewPushRpcCmd() *PushRpcCmd { func NewPushRpcCmd() *PushRpcCmd {
var pushConfig push.Config var pushConfig push.Config
ret := &PushRpcCmd{pushConfig: pushConfig} ret := &PushRpcCmd{pushConfig: &pushConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMPushCfgFileName: &pushConfig.RpcConfig, OpenIMPushCfgFileName: &pushConfig.RpcConfig,
RedisConfigFileName: &pushConfig.RedisConfig, RedisConfigFileName: &pushConfig.RedisConfig,
@ -59,5 +59,5 @@ func (a *PushRpcCmd) Exec() error {
func (a *PushRpcCmd) preRunE() error { func (a *PushRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.pushConfig.ZookeeperConfig, &a.pushConfig.RpcConfig.Prometheus, a.pushConfig.RpcConfig.RPC.ListenIP, 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.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 { func (r *RootCmd) persistentPreRun(cmd *cobra.Command, opts ...func(*CmdOpts)) error {
cmdOpts := r.applyOptions(opts...) cmdOpts := r.applyOptions(opts...)
fmt.Println("config", cmdOpts.configMap)
if err := r.initializeConfiguration(cmd, cmdOpts); err != nil { if err := r.initializeConfiguration(cmd, cmdOpts); err != nil {
return err return err
} }

@ -27,12 +27,12 @@ type ThirdRpcCmd struct {
*RootCmd *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
thirdConfig third.Config thirdConfig *third.Config
} }
func NewThirdRpcCmd() *ThirdRpcCmd { func NewThirdRpcCmd() *ThirdRpcCmd {
var thirdConfig third.Config var thirdConfig third.Config
ret := &ThirdRpcCmd{thirdConfig: thirdConfig} ret := &ThirdRpcCmd{thirdConfig: &thirdConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCThirdCfgFileName: &thirdConfig.RpcConfig, OpenIMRPCThirdCfgFileName: &thirdConfig.RpcConfig,
RedisConfigFileName: &thirdConfig.RedisConfig, RedisConfigFileName: &thirdConfig.RedisConfig,
@ -58,5 +58,5 @@ func (a *ThirdRpcCmd) Exec() error {
func (a *ThirdRpcCmd) preRunE() error { func (a *ThirdRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.thirdConfig.ZookeeperConfig, &a.thirdConfig.RpcConfig.Prometheus, a.thirdConfig.RpcConfig.RPC.ListenIP, 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.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 *RootCmd
ctx context.Context ctx context.Context
configMap map[string]any configMap map[string]any
userConfig user.Config userConfig *user.Config
} }
func NewUserRpcCmd() *UserRpcCmd { func NewUserRpcCmd() *UserRpcCmd {
var userConfig user.Config var userConfig user.Config
ret := &UserRpcCmd{userConfig: userConfig} ret := &UserRpcCmd{userConfig: &userConfig}
ret.configMap = map[string]any{ ret.configMap = map[string]any{
OpenIMRPCUserCfgFileName: &userConfig.RpcConfig, OpenIMRPCUserCfgFileName: &userConfig.RpcConfig,
RedisConfigFileName: &userConfig.RedisConfig, RedisConfigFileName: &userConfig.RedisConfig,
@ -59,5 +59,5 @@ func (a *UserRpcCmd) Exec() error {
func (a *UserRpcCmd) preRunE() error { func (a *UserRpcCmd) preRunE() error {
return startrpc.Start(a.ctx, &a.userConfig.ZookeeperConfig, &a.userConfig.RpcConfig.Prometheus, a.userConfig.RpcConfig.RPC.ListenIP, 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.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 package config
import ( import (
"fmt"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/openimsdk/tools/errs" "github.com/openimsdk/tools/errs"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -24,6 +23,5 @@ func LoadConfig(path string, envPrefix string, config any) error {
}); err != nil { }); err != nil {
return errs.WrapMsg(err, "failed to unmarshal config", "path", path, "envPrefix", envPrefix) 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 return nil
} }

Loading…
Cancel
Save