test-errcode
wangchuxiao 2 years ago
parent 046d645ef6
commit 0c98231fcd

@ -9,10 +9,14 @@ import (
) )
func main() { func main() {
rpcCmd := cmd.NewRpcCmd() authCmd := cmd.NewAuthCmd()
rpcCmd.AddPortFlag() authCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag() authCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec2(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil { if err := authCmd.Execute(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := authCmd.StartSvr(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
} }

@ -20,7 +20,7 @@ type Auth struct {
} }
func (o *Auth) client() (auth.AuthClient, error) { 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 { if err != nil {
return nil, err return nil, err
} }

@ -1,5 +0,0 @@
package cmd
type AuthCmd struct {
*RpcCmd
}

@ -8,6 +8,8 @@ import (
type RootCmd struct { type RootCmd struct {
Command cobra.Command Command cobra.Command
port int
prometheusPort int
} }
func NewRootCmd() (rootCmd *RootCmd) { func NewRootCmd() (rootCmd *RootCmd) {
@ -50,6 +52,10 @@ func (r *RootCmd) getPortFlag(cmd *cobra.Command) int {
return port return port
} }
func (r *RootCmd) GetPortFlag() int {
return r.port
}
func (r *RootCmd) AddPrometheusPortFlag() { func (r *RootCmd) AddPrometheusPortFlag() {
r.Command.Flags().String(constant.FlagPrometheusPort, "", "server prometheus listen port") r.Command.Flags().String(constant.FlagPrometheusPort, "", "server prometheus listen port")
} }
@ -59,6 +65,10 @@ func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) int {
return port return port
} }
func (r *RootCmd) GetPrometheusPortFlag() int {
return r.prometheusPort
}
func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error { func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error {
configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf) configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf)
return config.InitConfig(configFolderPath) return config.InitConfig(configFolderPath)

@ -7,33 +7,23 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
type RpcCmd struct { type AuthCmd struct {
*RootCmd *RootCmd
} }
func NewRpcCmd() *RpcCmd { func NewAuthCmd() *AuthCmd {
rpcCmd := &RpcCmd{NewRootCmd()} authCmd := &AuthCmd{NewRootCmd()}
return rpcCmd return authCmd
} }
func (r *RpcCmd) addRpc(rpcRegisterName string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) { func (a *AuthCmd) Execute() error {
r.Command.RunE = func(cmd *cobra.Command, args []string) error { a.Command.Run = func(cmd *cobra.Command, args []string) {
return startrpc.Start(r.getPortFlag(cmd), rpcRegisterName, r.getPrometheusPortFlag(cmd), rpcFn) a.port = a.getPortFlag(cmd)
a.prometheusPort = a.getPrometheusPortFlag(cmd)
} }
return a.Execute()
} }
func (r *RpcCmd) Exec(rpcRegisterName string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error { func (a *AuthCmd) StartSvr(name string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error {
r.addRpc(rpcRegisterName, rpcFn) return startrpc.Start(a.GetPortFlag(), name, a.GetPrometheusPortFlag(), 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()
} }

@ -165,7 +165,7 @@ type config struct {
OpenImPushName string `yaml:"openImPushName"` OpenImPushName string `yaml:"openImPushName"`
OpenImMessageGatewayName string `yaml:"openImMessageGatewayName"` OpenImMessageGatewayName string `yaml:"openImMessageGatewayName"`
OpenImGroupName string `yaml:"openImGroupName"` OpenImGroupName string `yaml:"openImGroupName"`
OpenImAuthName *string `yaml:"openImAuthName"` OpenImAuthName string `yaml:"openImAuthName"`
OpenImConversationName string `yaml:"openImConversationName"` OpenImConversationName string `yaml:"openImConversationName"`
OpenImCacheName string `yaml:"openImCacheName"` OpenImCacheName string `yaml:"openImCacheName"`
OpenImRtcName string `yaml:"openImRtcName"` OpenImRtcName string `yaml:"openImRtcName"`

Loading…
Cancel
Save