diff --git a/internal/msggateway/init.go b/internal/msggateway/init.go index 7a4b6d6ad..ce63fb21a 100644 --- a/internal/msggateway/init.go +++ b/internal/msggateway/init.go @@ -18,9 +18,12 @@ import ( "fmt" "time" + "github.com/OpenIMSDK/tools/utils" + "github.com/openimsdk/open-im-server/v3/pkg/common/config" ) +// RunWsAndServer run ws server func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error { fmt.Println( "start rpc/msg_gateway server, port: ", @@ -42,7 +45,7 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error { go func() { err := hubServer.Start() if err != nil { - panic(err.Error()) + panic(utils.Wrap1(err)) } }() return hubServer.LongConnServer.Run() diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index f220ab7c1..4ea36cfeb 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -23,6 +23,7 @@ import ( "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/log" + "github.com/openimsdk/open-im-server/v3/pkg/common/config" ) diff --git a/pkg/common/startrpc/doc.go b/pkg/common/startrpc/doc.go index 1d5fd6787..206e7900f 100644 --- a/pkg/common/startrpc/doc.go +++ b/pkg/common/startrpc/doc.go @@ -12,4 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -package startrpc // import "github.com/openimsdk/open-im-server/v3/pkg/common/startrpc" +// Package startrpc start rpc server. +package startrpc diff --git a/pkg/common/startrpc/start.go b/pkg/common/startrpc/start.go index 19da8a586..2aeff3cf0 100644 --- a/pkg/common/startrpc/start.go +++ b/pkg/common/startrpc/start.go @@ -16,11 +16,12 @@ package startrpc import ( "fmt" - "github.com/openimsdk/open-im-server/v3/pkg/common/config" - "github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register" "net" "strconv" + "github.com/openimsdk/open-im-server/v3/pkg/common/config" + "github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register" + grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -32,6 +33,7 @@ import ( "github.com/OpenIMSDK/tools/utils" ) +// Start rpc server. func Start( rpcPort int, rpcRegisterName string, @@ -39,16 +41,8 @@ func Start( rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption, ) error { - fmt.Println( - "start", - rpcRegisterName, - "server, port: ", - rpcPort, - "prometheusPort:", - prometheusPort, - ", OpenIM version: ", - config.Version, - ) + fmt.Printf("start %s server, port: %d, prometheusPort: %d, OpenIM version: %s", + rpcRegisterName, rpcPort, prometheusPort, config.Version) listener, err := net.Listen( "tcp", net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort)), @@ -63,11 +57,10 @@ func Start( zookeeper.WithFreq(time.Hour), zookeeper.WithUserNameAndPassword( config.Config.Zookeeper.Username, config.Config.Zookeeper.Password, - ), zookeeper.WithRoundRobin(), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))*/ - if err != nil { + ), zookeeper.WithRoundRobin(), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))*/if err != nil { return utils.Wrap1(err) } - //defer zkClient.CloseZK() + // defer zkClient.CloseZK() zkClient.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP) if err != nil { @@ -108,5 +101,6 @@ func Start( } } }() + return utils.Wrap1(srv.Serve(listener)) }