mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
script
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
package cmd
|
||||
|
||||
type AuthCmd struct {
|
||||
*RpcCmd
|
||||
}
|
||||
+11
-1
@@ -7,7 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type RootCmd struct {
|
||||
Command cobra.Command
|
||||
Command cobra.Command
|
||||
port int
|
||||
prometheusPort int
|
||||
}
|
||||
|
||||
func NewRootCmd() (rootCmd *RootCmd) {
|
||||
@@ -50,6 +52,10 @@ func (r *RootCmd) getPortFlag(cmd *cobra.Command) int {
|
||||
return port
|
||||
}
|
||||
|
||||
func (r *RootCmd) GetPortFlag() int {
|
||||
return r.port
|
||||
}
|
||||
|
||||
func (r *RootCmd) AddPrometheusPortFlag() {
|
||||
r.Command.Flags().String(constant.FlagPrometheusPort, "", "server prometheus listen port")
|
||||
}
|
||||
@@ -59,6 +65,10 @@ func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) int {
|
||||
return port
|
||||
}
|
||||
|
||||
func (r *RootCmd) GetPrometheusPortFlag() int {
|
||||
return r.prometheusPort
|
||||
}
|
||||
|
||||
func (r *RootCmd) getConfFromCmdAndInit(cmdLines *cobra.Command) error {
|
||||
configFolderPath, _ := cmdLines.Flags().GetString(constant.FlagConf)
|
||||
return config.InitConfig(configFolderPath)
|
||||
|
||||
+11
-21
@@ -7,33 +7,23 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type RpcCmd struct {
|
||||
type AuthCmd struct {
|
||||
*RootCmd
|
||||
}
|
||||
|
||||
func NewRpcCmd() *RpcCmd {
|
||||
rpcCmd := &RpcCmd{NewRootCmd()}
|
||||
return rpcCmd
|
||||
func NewAuthCmd() *AuthCmd {
|
||||
authCmd := &AuthCmd{NewRootCmd()}
|
||||
return authCmd
|
||||
}
|
||||
|
||||
func (r *RpcCmd) addRpc(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 (a *AuthCmd) Execute() error {
|
||||
a.Command.Run = func(cmd *cobra.Command, args []string) {
|
||||
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 {
|
||||
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()
|
||||
func (a *AuthCmd) StartSvr(name string, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error {
|
||||
return startrpc.Start(a.GetPortFlag(), name, a.GetPrometheusPortFlag(), rpcFn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user