From 8f3a59de219ba445f203005c09b617f6856e92ca Mon Sep 17 00:00:00 2001 From: lbbniu Date: Fri, 13 Jan 2023 21:07:17 +0800 Subject: [PATCH] fix(examples): custom proto server and GetCommunicator replace NewCommunicator --- examples/CmakeServer/client/client.go | 2 +- examples/ContextTestServer/client/client.go | 2 +- examples/ContextTestServer/debugtool/dumpstack.go | 2 +- examples/CustomProtoServer/CustomProtoImp.go | 10 +++++----- examples/CustomProtoServer/client/client.go | 10 +++++----- examples/CustomProtoServer/debugtool/dumpstack.go | 2 +- examples/EchoClientServer/EchoClientServer.go | 2 +- examples/EchoClientServer/client/client.go | 2 +- examples/EchoTestServer/client/client.go | 2 +- examples/PushServer/client/client.go | 2 +- examples/PushServer/debugtool/dumpstack.go | 2 +- examples/TlsTestServer/client/client.go | 2 +- examples/TlsTestServer/debugtool/dumpstack.go | 2 +- examples/ZipkinTraceClient/ZipkinTraceClient.go | 2 +- examples/ZipkinTraceClient/client/client.go | 2 +- examples/trace/TarsTraceBackServer/client/client.go | 2 +- .../trace/TarsTraceBackServer/debugtool/dumpstack.go | 2 +- examples/trace/TarsTraceFrontServer/Frontend_imp.go | 2 +- examples/trace/TarsTraceFrontServer/client/client.go | 2 +- .../trace/TarsTraceFrontServer/debugtool/dumpstack.go | 2 +- 20 files changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/CmakeServer/client/client.go b/examples/CmakeServer/client/client.go index c9585e12..4302bf5a 100644 --- a/examples/CmakeServer/client/client.go +++ b/examples/CmakeServer/client/client.go @@ -9,7 +9,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("StressTest.EchoTestServer.EchoTestObj@tcp -h 127.0.0.1 -p 10015 -t 60000") app := new(StressTest.EchoTest) comm.StringToProxy(obj, app) diff --git a/examples/ContextTestServer/client/client.go b/examples/ContextTestServer/client/client.go index 42d33105..be9bc7fe 100644 --- a/examples/ContextTestServer/client/client.go +++ b/examples/ContextTestServer/client/client.go @@ -10,7 +10,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("StressTest.ContextTestServer.ContextTestObj@tcp -h 127.0.0.1 -p 10028 -t 60000") app := new(StressTest.ContextTest) comm.StringToProxy(obj, app) diff --git a/examples/ContextTestServer/debugtool/dumpstack.go b/examples/ContextTestServer/debugtool/dumpstack.go index 34c2593e..a5333e87 100644 --- a/examples/ContextTestServer/debugtool/dumpstack.go +++ b/examples/ContextTestServer/debugtool/dumpstack.go @@ -7,7 +7,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("StressTest.ContextTestServer.ContextTestObjObj@tcp -h 127.0.0.1 -p 10014 -t 60000") app := new(adminf.AdminF) comm.StringToProxy(obj, app) diff --git a/examples/CustomProtoServer/CustomProtoImp.go b/examples/CustomProtoServer/CustomProtoImp.go index fa274e59..da3a20cf 100755 --- a/examples/CustomProtoServer/CustomProtoImp.go +++ b/examples/CustomProtoServer/CustomProtoImp.go @@ -24,22 +24,22 @@ func (s *CustomProtocolImp) DoClose(ctx context.Context) { // ParsePackage parse request package func (s *CustomProtocolImp) ParsePackage(buff []byte) (int, int) { if len(buff) < 4 { - return 0, transport.PACKAGE_LESS + return 0, transport.PackageLess } if len(buff) > 10485760 { - return 0, transport.PACKAGE_ERROR + return 0, transport.PackageError } var idx = bytes.Index(buff, []byte("\n")) if idx > 0 { - return idx + 1, transport.PACKAGE_FULL + return idx + 1, transport.PackageFull } - return 0, transport.PACKAGE_LESS + return 0, transport.PackageLess } // Invoke process request and send response func (s *CustomProtocolImp) Invoke(ctx context.Context, req []byte) []byte { - fmt.Println("req:", req) + fmt.Print("req:", string(req)) reqMap, err := url.ParseQuery(strings.TrimSpace(string(req))) if err != nil { return []byte("ret=-1&msg=invalid_format\n") diff --git a/examples/CustomProtoServer/client/client.go b/examples/CustomProtoServer/client/client.go index b1a5fa1d..f560458a 100755 --- a/examples/CustomProtoServer/client/client.go +++ b/examples/CustomProtoServer/client/client.go @@ -14,22 +14,22 @@ type MyClient struct { } func (c *MyClient) Recv(pkg []byte) { - fmt.Println("recv:", string(pkg)) + fmt.Print("recv:", string(pkg)) c.recvCount++ } func (c *MyClient) ParsePackage(buff []byte) (pkgLen, status int) { if len(buff) < 4 { - return 0, transport.PACKAGE_LESS + return 0, transport.PackageLess } if len(buff) > 10485760 { - return 0, transport.PACKAGE_ERROR + return 0, transport.PackageError } var idx = bytes.Index(buff, []byte("\n")) if idx > 0 { - return idx + 1, transport.PACKAGE_FULL + return idx + 1, transport.PackageFull } - return 0, transport.PACKAGE_LESS + return 0, transport.PackageLess } func getMsg(name string, idx int) []byte { diff --git a/examples/CustomProtoServer/debugtool/dumpstack.go b/examples/CustomProtoServer/debugtool/dumpstack.go index 7d14e438..53b20d53 100644 --- a/examples/CustomProtoServer/debugtool/dumpstack.go +++ b/examples/CustomProtoServer/debugtool/dumpstack.go @@ -8,7 +8,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Test.CustomProtoServer.CustomProtoObj@tcp -h 127.0.0.1 -p 10015 -t 60000") app := new(adminf.AdminF) comm.StringToProxy(obj, app) diff --git a/examples/EchoClientServer/EchoClientServer.go b/examples/EchoClientServer/EchoClientServer.go index 3e5e0a04..cf2363d2 100644 --- a/examples/EchoClientServer/EchoClientServer.go +++ b/examples/EchoClientServer/EchoClientServer.go @@ -55,7 +55,7 @@ func (imp *EchoClientImp) Sub(a int32, b int32, c *int32) (int32, error) { } func main() { //Init servant - comm = tars.NewCommunicator() + comm = tars.GetCommunicator() // client log = tars.GetDayLogger("report", 1) diff --git a/examples/EchoClientServer/client/client.go b/examples/EchoClientServer/client/client.go index 96d1fb8a..b6195776 100644 --- a/examples/EchoClientServer/client/client.go +++ b/examples/EchoClientServer/client/client.go @@ -9,7 +9,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("StressTest.EchoClientServer.EchoClientObj@tcp -h 127.0.0.1 -p 11015 -t 60000") app := new(StressTest.EchoClient) comm.StringToProxy(obj, app) diff --git a/examples/EchoTestServer/client/client.go b/examples/EchoTestServer/client/client.go index f00f6734..5d4a1ed8 100644 --- a/examples/EchoTestServer/client/client.go +++ b/examples/EchoTestServer/client/client.go @@ -9,7 +9,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("StressTest.EchoTestServer.EchoTestObj@tcp -h 127.0.0.1 -p 12015 -t 60000") app := new(StressTest.EchoTest) comm.StringToProxy(obj, app) diff --git a/examples/PushServer/client/client.go b/examples/PushServer/client/client.go index 4054479c..0b65b1b7 100644 --- a/examples/PushServer/client/client.go +++ b/examples/PushServer/client/client.go @@ -13,7 +13,7 @@ func callback(data []byte) { } func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := "TestApp.PushServer.MessageObj@tcp -h 127.0.0.1 -p 10015 -t 60000" client := push.NewClient(callback) comm.StringToProxy(obj, client) diff --git a/examples/PushServer/debugtool/dumpstack.go b/examples/PushServer/debugtool/dumpstack.go index 7b807009..e6600d67 100644 --- a/examples/PushServer/debugtool/dumpstack.go +++ b/examples/PushServer/debugtool/dumpstack.go @@ -8,7 +8,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := "TestApp.PushServer.MessageObj@tcp -h 127.0.0.1 -p 10014 -t 60000" app := new(adminf.AdminF) comm.StringToProxy(obj, app) diff --git a/examples/TlsTestServer/client/client.go b/examples/TlsTestServer/client/client.go index d104dd66..8b28d322 100644 --- a/examples/TlsTestServer/client/client.go +++ b/examples/TlsTestServer/client/client.go @@ -10,7 +10,7 @@ import ( func main() { tars.ServerConfigPath = "config.conf" - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("App.TlsTestServer.TlsObj@ssl -h 127.0.0.1 -p 13015 -t 6000000000") app := new(App.Tls) comm.StringToProxy(obj, app) diff --git a/examples/TlsTestServer/debugtool/dumpstack.go b/examples/TlsTestServer/debugtool/dumpstack.go index 56e5ad98..50d5734a 100644 --- a/examples/TlsTestServer/debugtool/dumpstack.go +++ b/examples/TlsTestServer/debugtool/dumpstack.go @@ -8,7 +8,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("App.TlsTestServer.TlsObj@tcp -h 127.0.0.1 -p 10014 -t 60000") app := new(adminf.AdminF) comm.StringToProxy(obj, app) diff --git a/examples/ZipkinTraceClient/ZipkinTraceClient.go b/examples/ZipkinTraceClient/ZipkinTraceClient.go index 7821208f..2d0a9f1f 100644 --- a/examples/ZipkinTraceClient/ZipkinTraceClient.go +++ b/examples/ZipkinTraceClient/ZipkinTraceClient.go @@ -11,7 +11,7 @@ import ( ) var sapp = new(ZipkinTraceApp.ZipkinTrace) -var comm = tars.NewCommunicator() +var comm = tars.GetCommunicator() var logger = tars.GetLogger("zipkin") func main() { // Init servant diff --git a/examples/ZipkinTraceClient/client/client.go b/examples/ZipkinTraceClient/client/client.go index 99473c3a..712785e5 100644 --- a/examples/ZipkinTraceClient/client/client.go +++ b/examples/ZipkinTraceClient/client/client.go @@ -9,7 +9,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("ZipkinTraceApp.ZipkinTraceClient.ZipkinClientObj@tcp -h 127.0.0.1 -p 14015 -t 60000") app := new(ZipkinTraceApp.ZipkinClient) comm.StringToProxy(obj, app) diff --git a/examples/trace/TarsTraceBackServer/client/client.go b/examples/trace/TarsTraceBackServer/client/client.go index d6374723..88e72414 100644 --- a/examples/trace/TarsTraceBackServer/client/client.go +++ b/examples/trace/TarsTraceBackServer/client/client.go @@ -9,7 +9,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 20015 -t 60000") app := new(Trace.Backend) comm.StringToProxy(obj, app) diff --git a/examples/trace/TarsTraceBackServer/debugtool/dumpstack.go b/examples/trace/TarsTraceBackServer/debugtool/dumpstack.go index 6c99f115..2d7a4d26 100644 --- a/examples/trace/TarsTraceBackServer/debugtool/dumpstack.go +++ b/examples/trace/TarsTraceBackServer/debugtool/dumpstack.go @@ -8,7 +8,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 10014 -t 60000") app := new(adminf.AdminF) comm.StringToProxy(obj, app) diff --git a/examples/trace/TarsTraceFrontServer/Frontend_imp.go b/examples/trace/TarsTraceFrontServer/Frontend_imp.go index eb183e83..3288da9d 100755 --- a/examples/trace/TarsTraceFrontServer/Frontend_imp.go +++ b/examples/trace/TarsTraceFrontServer/Frontend_imp.go @@ -15,7 +15,7 @@ type FrontendImp struct { // Init servant init func (imp *FrontendImp) Init() error { //initialize servant here: - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 20015 -t 60000") app := new(Trace.Backend) comm.StringToProxy(obj, app) diff --git a/examples/trace/TarsTraceFrontServer/client/client.go b/examples/trace/TarsTraceFrontServer/client/client.go index 38a1ebcb..7d898682 100644 --- a/examples/trace/TarsTraceFrontServer/client/client.go +++ b/examples/trace/TarsTraceFrontServer/client/client.go @@ -11,7 +11,7 @@ import ( func main() { tars.ServerConfigPath = "config.conf" - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Trace.TarsTraceFrontServer.FrontendObj@tcp -h 127.0.0.1 -p 10015 -t 60000") app := new(Trace.Frontend) comm.StringToProxy(obj, app) diff --git a/examples/trace/TarsTraceFrontServer/debugtool/dumpstack.go b/examples/trace/TarsTraceFrontServer/debugtool/dumpstack.go index f133698c..84c8a426 100644 --- a/examples/trace/TarsTraceFrontServer/debugtool/dumpstack.go +++ b/examples/trace/TarsTraceFrontServer/debugtool/dumpstack.go @@ -8,7 +8,7 @@ import ( ) func main() { - comm := tars.NewCommunicator() + comm := tars.GetCommunicator() obj := fmt.Sprintf("Trace.TarsTraceFrontServer.FrontendObj@tcp -h 127.0.0.1 -p 10014 -t 60000") app := new(adminf.AdminF) comm.StringToProxy(obj, app)