You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/cmd/rpc.go

36 lines
908 B

2 years ago
package cmd
import (
2 years ago
"OpenIM/internal/startrpc"
2 years ago
"OpenIM/pkg/common/config"
2 years ago
"OpenIM/pkg/discoveryregistry"
2 years ago
"fmt"
2 years ago
"github.com/spf13/cobra"
"google.golang.org/grpc"
)
type RpcCmd struct {
*RootCmd
2 years ago
rpcRegisterName string
2 years ago
}
2 years ago
func NewRpcCmd(rpcRegisterName string) *RpcCmd {
2 years ago
rpcCmd := &RpcCmd{NewRootCmd(), rpcRegisterName}
2 years ago
fmt.Println("line 18", *rpcCmd, rpcCmd, rpcRegisterName, config.Config.RpcRegisterName)
2 years ago
return rpcCmd
2 years ago
}
2 years ago
func (r *RpcCmd) AddRpc(rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) {
2 years ago
r.Command.RunE = func(cmd *cobra.Command, args []string) error {
2 years ago
return startrpc.Start(r.getPortFlag(cmd), r.rpcRegisterName, r.getPrometheusPortFlag(cmd), rpcFn)
2 years ago
}
}
2 years ago
func (r *RpcCmd) Exec(rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error) error {
2 years ago
fmt.Println(r)
2 years ago
r.AddRpc(rpcFn)
2 years ago
fmt.Println(r)
2 years ago
return r.Execute()
}