Commit 27823bad authored by AlexStocks's avatar AlexStocks

Mod: add protocol

parent 52f81ec7
......@@ -21,7 +21,6 @@ import (
import (
"github.com/AlexStocks/getty-examples/rpc/proto"
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/log"
"github.com/AlexStocks/goext/net"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
......@@ -45,7 +44,7 @@ func main() {
initProfiling()
initClient()
gxlog.CInfo("%s starts successfull! its version=%s\n", conf.AppName, Version)
// gxlog.CInfo("%s starts successfull! its version=%s\n", conf.AppName, Version)
log.Info("%s starts successfull! its version=%s\n", conf.AppName, Version)
go test()
......@@ -114,29 +113,29 @@ func testJSON() {
testRsp := rpc_examples.TestRsp{}
err := client.Call(rpc.CodecJson, "127.0.0.1:20000", ts.Service(), "Test", &testReq, &testRsp)
if err != nil {
log.Error("client.Call(TestService::Test) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(Json, TestService::Test) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Test(param:%#v) = res:%s", testReq, testRsp)
log.Info("TestService::Test(Json, param:%#v) = res:%s", testReq, testRsp)
addReq := rpc_examples.AddReq{1, 10}
addRsp := rpc_examples.AddRsp{}
err = client.Call(rpc.CodecJson, "127.0.0.1:10000", ts.Service(), "Add", &addReq, &addRsp)
if err != nil {
log.Error("client.Call(TestService::Add) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(Json, TestService::Add) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Add(req:%#v) = res:%#v", addReq, addRsp)
log.Info("TestService::Add(Json, req:%#v) = res:%#v", addReq, addRsp)
errReq := rpc_examples.ErrReq{1}
errRsp := rpc_examples.ErrRsp{}
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", ts.Service(), "Err", &errReq, &errRsp)
if err != nil {
// error test case, this invocation should step into this branch.
log.Error("client.Call(TestService::Err) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(Json, TestService::Err) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Err(req:%#v) = res:%s", errReq, errRsp)
log.Info("TestService::Err(Json, req:%#v) = res:%s", errReq, errRsp)
}
func testProtobuf() {
......@@ -145,33 +144,33 @@ func testProtobuf() {
testRsp := rpc_examples.TestRsp{}
err := client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", ts.Service(), "Test", &testReq, &testRsp)
if err != nil {
log.Error("client.Call(TestService::Test) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(protobuf, TestService::Test) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Test(param:%#v) = res:%s", testReq, testRsp)
log.Info("TestService::Test(protobuf, param:%#v) = res:%s", testReq, testRsp)
addReq := rpc_examples.AddReq{1, 10}
addRsp := rpc_examples.AddRsp{}
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:10000", ts.Service(), "Add", &addReq, &addRsp)
if err != nil {
log.Error("client.Call(TestService::Add) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(protobuf, TestService::Add) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Add(req:%#v) = res:%#v", addReq, addRsp)
log.Info("TestService::Add(protobuf, req:%#v) = res:%#v", addReq, addRsp)
errReq := rpc_examples.ErrReq{1}
errRsp := rpc_examples.ErrRsp{}
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", ts.Service(), "Err", &errReq, &errRsp)
if err != nil {
// error test case, this invocation should step into this branch.
log.Error("client.Call(TestService::Err) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(protobuf, TestService::Err) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestService::Err(req:%#v) = res:%#v", errReq, errRsp)
log.Info("TestService::Err(protobuf, req:%#v) = res:%#v", errReq, errRsp)
}
func test() {
testJSON()
// testProtobuf()
testProtobuf()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment