Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
57fda234
Commit
57fda234
authored
Aug 06, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add: protobuf test example
parent
1e853451
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
5 deletions
+66
-5
readme.md
readme.md
+22
-1
main.go
rpc/client/app/main.go
+42
-2
version.go
rpc/client/app/version.go
+1
-1
version.go
rpc/server/app/version.go
+1
-1
No files found.
readme.md
View file @
57fda234
...
...
@@ -22,7 +22,7 @@ To run the example, start the server:
Next, start the client:
$ cd tcp-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
$ cd
echo/
tcp-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
## getty example2: ws-echo ##
---
...
...
@@ -42,3 +42,24 @@ Next, start the go client:
Or start the js client:
$ cd echo/ws-echo/js-client/ && open index.html in a internet browser(like chrome or ie or firefox etc).
## getty example3: rpc ##
---
This example shows a simple rpc client and server.
The server sends back rpc response to client. The client sends rpc requests to the rpc server and prints all messages received.
To run the example on linux, start the server:
$ cd rpc/server/ && sh assembly/linux/test.sh && cd target/linux/rpc_server-0.9.2-20180806-1559-test/ && sh bin/load.sh start
Next, start the go client:
$ cd rpc/client/ && sh assembly/linux/test.sh && cd target/linux/rpc_client-0.9.2-20180806-1559-test/ && sh bin/load.sh start
What's more, if you run this example on mac, the server compile command should be:
$ cd rpc/server/ && sh assembly/mac/test.sh && cd target/darwin/rpc_server-0.9.2-20180806-1559-test/ && sh bin/load.sh start
$ cd rpc/client/ && sh assembly/mac/test.sh && cd target/darwin/rpc_client-0.9.2-20180806-1559-test/ && sh bin/load.sh start
rpc/client/app/main.go
View file @
57fda234
...
...
@@ -107,7 +107,7 @@ func initSignal() {
}
}
func
test
()
{
func
test
JSON
()
{
var
(
err
error
testResult
string
...
...
@@ -126,7 +126,7 @@ func test() {
log
.
Error
(
"client.Call(TestRpc::Add) = error:%s"
,
jerrors
.
ErrorStack
(
err
))
return
}
log
.
Info
(
"TestRpc::Add(1) = res:%
s
"
,
addResult
)
log
.
Info
(
"TestRpc::Add(1) = res:%
d
"
,
addResult
)
var
errResult
int
err
=
client
.
Call
(
rpc
.
CodecJson
,
"127.0.0.1:20000"
,
"TestRpc"
,
"Err"
,
2
,
&
errResult
)
...
...
@@ -137,3 +137,43 @@ func test() {
}
log
.
Info
(
"TestRpc::Err(2) = res:%s"
,
errResult
)
}
func
testProtobuf
()
{
var
(
err
error
testResult
string
)
param
:=
TestABC
{
"aaa"
,
"bbb"
,
"ccc"
}
err
=
client
.
Call
(
rpc
.
CodecProtobuf
,
"127.0.0.1:20000"
,
"TestRpc"
,
"Test"
,
param
,
&
testResult
)
if
err
!=
nil
{
log
.
Error
(
"client.Call(TestRpc::Test) = error:%s"
,
jerrors
.
ErrorStack
(
err
))
return
}
log
.
Info
(
"TestRpc::Test(param:%#v) = res:%s"
,
param
,
testResult
)
var
addResult
int
err
=
client
.
Call
(
rpc
.
CodecProtobuf
,
"127.0.0.1:20000"
,
"TestRpc"
,
"Add"
,
1
,
&
addResult
)
if
err
!=
nil
{
log
.
Error
(
"client.Call(TestRpc::Add) = error:%s"
,
jerrors
.
ErrorStack
(
err
))
return
}
log
.
Info
(
"TestRpc::Add(1) = res:%d"
,
addResult
)
var
errResult
int
err
=
client
.
Call
(
rpc
.
CodecProtobuf
,
"127.0.0.1:20000"
,
"TestRpc"
,
"Err"
,
2
,
&
errResult
)
if
err
!=
nil
{
// error test case, this invocation should step into this branch.
log
.
Error
(
"client.Call(TestRpc::Err) = error:%s"
,
jerrors
.
ErrorStack
(
err
))
return
}
log
.
Info
(
"TestRpc::Err(2) = res:%s"
,
errResult
)
}
func
test
()
{
gxlog
.
CInfo
(
"start to run json rpc example:
\n
"
)
testJSON
()
time
.
Sleep
(
2e9
)
gxlog
.
CInfo
(
"start to run protobuf rpc example:
\n
"
)
testJSON
()
}
rpc/client/app/version.go
View file @
57fda234
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
8.4
"
Version
=
"0.
9.2
"
)
rpc/server/app/version.go
View file @
57fda234
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
8.4
"
Version
=
"0.
9.2
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment