From 8904ebccbc792505a5d91e3c583f32a41d61b14b Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 9 Mar 2023 12:46:56 +0800 Subject: [PATCH] script --- cmd/rpc/auth/main.go | 2 +- internal/api/auth.go | 2 +- pkg/common/cmd/auth.go | 5 +++++ pkg/common/cmd/rpc.go | 11 +++++++++++ pkg/common/config/config.go | 22 +++++++++++----------- 5 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 pkg/common/cmd/auth.go diff --git a/cmd/rpc/auth/main.go b/cmd/rpc/auth/main.go index 609eab4a1..0e298263a 100644 --- a/cmd/rpc/auth/main.go +++ b/cmd/rpc/auth/main.go @@ -12,7 +12,7 @@ func main() { rpcCmd := cmd.NewRpcCmd() rpcCmd.AddPortFlag() rpcCmd.AddPrometheusPortFlag() - if err := rpcCmd.Exec(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil { + if err := rpcCmd.Exec(*config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil { fmt.Println(err.Error()) os.Exit(1) } diff --git a/internal/api/auth.go b/internal/api/auth.go index e997ba6aa..209196f78 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -20,7 +20,7 @@ type Auth struct { } func (o *Auth) client() (auth.AuthClient, error) { - conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImAuthName) + conn, err := o.c.GetConn(*config.Config.RpcRegisterName.OpenImAuthName) if err != nil { return nil, err } diff --git a/pkg/common/cmd/auth.go b/pkg/common/cmd/auth.go new file mode 100644 index 000000000..1d8f84aad --- /dev/null +++ b/pkg/common/cmd/auth.go @@ -0,0 +1,5 @@ +package cmd + +type AuthCmd struct { + *RpcCmd +} diff --git a/pkg/common/cmd/rpc.go b/pkg/common/cmd/rpc.go index 17ad0794d..5f204e096 100644 --- a/pkg/common/cmd/rpc.go +++ b/pkg/common/cmd/rpc.go @@ -26,3 +26,14 @@ func (r *RpcCmd) Exec(rpcRegisterName string, rpcFn func(client discoveryregistr r.addRpc(rpcRegisterName, rpcFn) return r.Execute() } + +func (r *RpcCmd) addRpc2(rpcRegisterName *string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) { + r.Command.RunE = func(cmd *cobra.Command, args []string) error { + return startrpc.Start(r.getPortFlag(cmd), *rpcRegisterName, r.getPrometheusPortFlag(cmd), rpcFn) + } +} + +func (r *RpcCmd) Exec2(rpcRegisterName *string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error { + r.addRpc2(rpcRegisterName, rpcFn) + return r.Execute() +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index ed0f5a0d9..97badb317 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -159,17 +159,17 @@ type config struct { OpenImThirdPort []int `yaml:"openImThirdPort"` } RpcRegisterName struct { - OpenImUserName string `yaml:"openImUserName"` - OpenImFriendName string `yaml:"openImFriendName"` - OpenImMsgName string `yaml:"openImMsgName"` - OpenImPushName string `yaml:"openImPushName"` - OpenImMessageGatewayName string `yaml:"openImMessageGatewayName"` - OpenImGroupName string `yaml:"openImGroupName"` - OpenImAuthName string `yaml:"openImAuthName"` - OpenImConversationName string `yaml:"openImConversationName"` - OpenImCacheName string `yaml:"openImCacheName"` - OpenImRtcName string `yaml:"openImRtcName"` - OpenImThirdName string `yaml:"openImThirdName"` + OpenImUserName string `yaml:"openImUserName"` + OpenImFriendName string `yaml:"openImFriendName"` + OpenImMsgName string `yaml:"openImMsgName"` + OpenImPushName string `yaml:"openImPushName"` + OpenImMessageGatewayName string `yaml:"openImMessageGatewayName"` + OpenImGroupName string `yaml:"openImGroupName"` + OpenImAuthName *string `yaml:"openImAuthName"` + OpenImConversationName string `yaml:"openImConversationName"` + OpenImCacheName string `yaml:"openImCacheName"` + OpenImRtcName string `yaml:"openImRtcName"` + OpenImThirdName string `yaml:"openImThirdName"` } Zookeeper struct { Schema string `yaml:"schema"`