Commit 6fcc015a authored by AlexStocks's avatar AlexStocks

Add: protobuf protocol file

parent 57fda234
package main
import (
"errors"
)
import (
log "github.com/AlexStocks/log4go"
)
type TestABC struct {
A, B, C string
}
type TestRpc struct {
i int
}
func (r *TestRpc) Service() string {
return "TestRpc"
}
func (r *TestRpc) Version() string {
return "v1.0"
}
func (r *TestRpc) Test(arg TestABC, res *string) error {
log.Debug("arg:%+v", arg)
*res = "this is a test"
return nil
}
func (r *TestRpc) Add(n int, res *int) error {
r.i += n
*res = r.i + 100
return nil
}
func (r *TestRpc) Err(n int, res *int) error {
return errors.New("this is a error test")
}
......@@ -19,6 +19,7 @@ import (
)
import (
"github.com/AlexStocks/getty-examples/rpc/proto"
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/log"
"github.com/AlexStocks/goext/net"
......@@ -108,72 +109,70 @@ func initSignal() {
}
func testJSON() {
var (
err error
testResult string
)
param := TestABC{"aaa", "bbb", "ccc"}
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", "TestRpc", "Test", param, &testResult)
testReq := rpc_examples.TestReq{"aaa", "bbb", "ccc"}
testRsp := rpc_examples.TestRsp{}
err := client.Call(rpc.CodecJson, "127.0.0.1:20000", "TestService", "Test", &testReq, &testRsp)
if err != nil {
log.Error("client.Call(TestRpc::Test) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(TestService::Test) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Test(param:%#v) = res:%s", param, testResult)
gxlog.CError("TestService::Test(param:%#v) = res:%s", testReq, testRsp)
return
var addResult int
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", "TestRpc", "Add", 1, &addResult)
err = client.Call(rpc.CodecJson, "127.0.0.1:10000", "TestService", "Add", 1, &addResult)
if err != nil {
log.Error("client.Call(TestRpc::Add) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(TestService::Add) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Add(1) = res:%d", addResult)
log.Info("TestService::Add(1) = res:%d", addResult)
var errResult int
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", "TestRpc", "Err", 2, &errResult)
err = client.Call(rpc.CodecJson, "127.0.0.1:10000", "TestService", "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))
log.Error("client.Call(TestService::Err) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Err(2) = res:%s", errResult)
log.Info("TestService::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)
testReq := rpc_examples.TestReq{"aaa", "bbb", "ccc"}
testRsp := rpc_examples.TestRsp{}
err := client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestService", "Test", &testReq, &testRsp)
if err != nil {
log.Error("client.Call(TestRpc::Test) = error:%s", jerrors.ErrorStack(err))
log.Error("client.Call(TestService::Test) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Test(param:%#v) = res:%s", param, testResult)
gxlog.CError("TestService::Test(param:%#v) = res:%s", testReq, testRsp)
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 addResult int
// err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestService", "Add", 1, &addResult)
// if err != nil {
// log.Error("client.Call(TestService::Add) = error:%s", jerrors.ErrorStack(err))
// return
// }
// log.Info("TestService::Add(1) = res:%d", addResult)
var errResult int
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestRpc", "Err", 2, &errResult)
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestService", "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))
log.Error("client.Call(TestService::Err) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Err(2) = res:%s", errResult)
log.Info("TestService::Err(2) = res:%s", errResult)
}
func test() {
gxlog.CInfo("start to run json rpc example:\n")
gxlog.CInfo("\nstart to run json rpc example:")
testJSON()
time.Sleep(2e9)
gxlog.CInfo("start to run protobuf rpc example:\n")
testJSON()
gxlog.CInfo("\nstart to run protobuf rpc example:")
testProtobuf()
}
......@@ -37,5 +37,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-client"
......@@ -37,5 +37,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-client"
......@@ -37,5 +37,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-client"
#!/usr/bin/env bash
# ******************************************************
# DESC :
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2017-09-04 22:53
# FILE : pb.sh
# ******************************************************
# descriptor.proto
gopath=~/test/golang/lib/src/github.com/gogo/protobuf/protobuf
# If you are using any gogo.proto extensions you will need to specify the
# proto_path to include the descriptor.proto and gogo.proto.
# gogo.proto is located in github.com/gogo/protobuf/gogoproto
gogopath=~/test/golang/lib/src/
# protoc -I=$gopath:$gogopath:/Users/alex/test/golang/lib/src/github.com/AlexStocks/goext/database/redis/:./ --gogoslick_out=Mredis_meta.proto="github.com/AlexStocks/goext/database/redis":../app/ response.proto
# protoc -I=$gopath:$gogopath:./ --gogoslick_out=Mrole.proto="github.com/AlexStocks/goext/database/registry":./src/ service.proto
protoc -I=$gopath:$gogopath:./ --gogoslick_out=./ service.proto
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: service.proto
/*
Package rpc_examples is a generated protocol buffer package.
It is generated from these files:
service.proto
It has these top-level messages:
TestReq
TestRsp
*/
package rpc_examples
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import strings "strings"
import reflect "reflect"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type TestReq struct {
A string `protobuf:"bytes,1,opt,name=A" json:"A"`
B string `protobuf:"bytes,2,opt,name=B" json:"B"`
C string `protobuf:"bytes,3,opt,name=C" json:"C"`
}
func (m *TestReq) Reset() { *m = TestReq{} }
func (*TestReq) ProtoMessage() {}
func (*TestReq) Descriptor() ([]byte, []int) { return fileDescriptorService, []int{0} }
type TestRsp struct {
A string `protobuf:"bytes,1,opt,name=A" json:"A"`
}
func (m *TestRsp) Reset() { *m = TestRsp{} }
func (*TestRsp) ProtoMessage() {}
func (*TestRsp) Descriptor() ([]byte, []int) { return fileDescriptorService, []int{1} }
func init() {
proto.RegisterType((*TestReq)(nil), "rpc_examples.TestReq")
proto.RegisterType((*TestRsp)(nil), "rpc_examples.TestRsp")
}
func (this *TestReq) VerboseEqual(that interface{}) error {
if that == nil {
if this == nil {
return nil
}
return fmt.Errorf("that == nil && this != nil")
}
that1, ok := that.(*TestReq)
if !ok {
that2, ok := that.(TestReq)
if ok {
that1 = &that2
} else {
return fmt.Errorf("that is not of type *TestReq")
}
}
if that1 == nil {
if this == nil {
return nil
}
return fmt.Errorf("that is type *TestReq but is nil && this != nil")
} else if this == nil {
return fmt.Errorf("that is type *TestReq but is not nil && this == nil")
}
if this.A != that1.A {
return fmt.Errorf("A this(%v) Not Equal that(%v)", this.A, that1.A)
}
if this.B != that1.B {
return fmt.Errorf("B this(%v) Not Equal that(%v)", this.B, that1.B)
}
if this.C != that1.C {
return fmt.Errorf("C this(%v) Not Equal that(%v)", this.C, that1.C)
}
return nil
}
func (this *TestReq) Equal(that interface{}) bool {
if that == nil {
if this == nil {
return true
}
return false
}
that1, ok := that.(*TestReq)
if !ok {
that2, ok := that.(TestReq)
if ok {
that1 = &that2
} else {
return false
}
}
if that1 == nil {
if this == nil {
return true
}
return false
} else if this == nil {
return false
}
if this.A != that1.A {
return false
}
if this.B != that1.B {
return false
}
if this.C != that1.C {
return false
}
return true
}
func (this *TestRsp) VerboseEqual(that interface{}) error {
if that == nil {
if this == nil {
return nil
}
return fmt.Errorf("that == nil && this != nil")
}
that1, ok := that.(*TestRsp)
if !ok {
that2, ok := that.(TestRsp)
if ok {
that1 = &that2
} else {
return fmt.Errorf("that is not of type *TestRsp")
}
}
if that1 == nil {
if this == nil {
return nil
}
return fmt.Errorf("that is type *TestRsp but is nil && this != nil")
} else if this == nil {
return fmt.Errorf("that is type *TestRsp but is not nil && this == nil")
}
if this.A != that1.A {
return fmt.Errorf("A this(%v) Not Equal that(%v)", this.A, that1.A)
}
return nil
}
func (this *TestRsp) Equal(that interface{}) bool {
if that == nil {
if this == nil {
return true
}
return false
}
that1, ok := that.(*TestRsp)
if !ok {
that2, ok := that.(TestRsp)
if ok {
that1 = &that2
} else {
return false
}
}
if that1 == nil {
if this == nil {
return true
}
return false
} else if this == nil {
return false
}
if this.A != that1.A {
return false
}
return true
}
func (this *TestReq) GoString() string {
if this == nil {
return "nil"
}
s := make([]string, 0, 7)
s = append(s, "&rpc_examples.TestReq{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "B: "+fmt.Sprintf("%#v", this.B)+",\n")
s = append(s, "C: "+fmt.Sprintf("%#v", this.C)+",\n")
s = append(s, "}")
return strings.Join(s, "")
}
func (this *TestRsp) GoString() string {
if this == nil {
return "nil"
}
s := make([]string, 0, 5)
s = append(s, "&rpc_examples.TestRsp{")
s = append(s, "A: "+fmt.Sprintf("%#v", this.A)+",\n")
s = append(s, "}")
return strings.Join(s, "")
}
func valueToGoStringService(v interface{}, typ string) string {
rv := reflect.ValueOf(v)
if rv.IsNil() {
return "nil"
}
pv := reflect.Indirect(rv).Interface()
return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
}
func (m *TestReq) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TestReq) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
dAtA[i] = 0xa
i++
i = encodeVarintService(dAtA, i, uint64(len(m.A)))
i += copy(dAtA[i:], m.A)
dAtA[i] = 0x12
i++
i = encodeVarintService(dAtA, i, uint64(len(m.B)))
i += copy(dAtA[i:], m.B)
dAtA[i] = 0x1a
i++
i = encodeVarintService(dAtA, i, uint64(len(m.C)))
i += copy(dAtA[i:], m.C)
return i, nil
}
func (m *TestRsp) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TestRsp) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
dAtA[i] = 0xa
i++
i = encodeVarintService(dAtA, i, uint64(len(m.A)))
i += copy(dAtA[i:], m.A)
return i, nil
}
func encodeFixed64Service(dAtA []byte, offset int, v uint64) int {
dAtA[offset] = uint8(v)
dAtA[offset+1] = uint8(v >> 8)
dAtA[offset+2] = uint8(v >> 16)
dAtA[offset+3] = uint8(v >> 24)
dAtA[offset+4] = uint8(v >> 32)
dAtA[offset+5] = uint8(v >> 40)
dAtA[offset+6] = uint8(v >> 48)
dAtA[offset+7] = uint8(v >> 56)
return offset + 8
}
func encodeFixed32Service(dAtA []byte, offset int, v uint32) int {
dAtA[offset] = uint8(v)
dAtA[offset+1] = uint8(v >> 8)
dAtA[offset+2] = uint8(v >> 16)
dAtA[offset+3] = uint8(v >> 24)
return offset + 4
}
func encodeVarintService(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *TestReq) Size() (n int) {
var l int
_ = l
l = len(m.A)
n += 1 + l + sovService(uint64(l))
l = len(m.B)
n += 1 + l + sovService(uint64(l))
l = len(m.C)
n += 1 + l + sovService(uint64(l))
return n
}
func (m *TestRsp) Size() (n int) {
var l int
_ = l
l = len(m.A)
n += 1 + l + sovService(uint64(l))
return n
}
func sovService(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozService(x uint64) (n int) {
return sovService(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (this *TestReq) String() string {
if this == nil {
return "nil"
}
s := strings.Join([]string{`&TestReq{`,
`A:` + fmt.Sprintf("%v", this.A) + `,`,
`B:` + fmt.Sprintf("%v", this.B) + `,`,
`C:` + fmt.Sprintf("%v", this.C) + `,`,
`}`,
}, "")
return s
}
func (this *TestRsp) String() string {
if this == nil {
return "nil"
}
s := strings.Join([]string{`&TestRsp{`,
`A:` + fmt.Sprintf("%v", this.A) + `,`,
`}`,
}, "")
return s
}
func valueToStringService(v interface{}) string {
rv := reflect.ValueOf(v)
if rv.IsNil() {
return "nil"
}
pv := reflect.Indirect(rv).Interface()
return fmt.Sprintf("*%v", pv)
}
func (m *TestReq) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TestReq: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TestReq: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field A", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthService
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.A = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field B", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthService
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.B = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field C", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthService
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.C = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipService(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthService
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *TestRsp) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TestRsp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TestRsp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field A", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowService
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthService
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.A = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipService(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthService
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipService(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowService
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowService
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowService
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthService
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowService
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipService(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthService = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowService = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("service.proto", fileDescriptorService) }
var fileDescriptorService = []byte{
// 196 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2d, 0x4e, 0x2d, 0x2a,
0xcb, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x29, 0x2a, 0x48, 0x8e, 0x4f,
0xad, 0x48, 0xcc, 0x2d, 0xc8, 0x49, 0x2d, 0x96, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2,
0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0x2b, 0x4a, 0x2a, 0x4d, 0x03, 0xf3,
0xc0, 0x1c, 0x30, 0x0b, 0xa2, 0x59, 0xc9, 0x95, 0x8b, 0x3d, 0x24, 0xb5, 0xb8, 0x24, 0x28, 0xb5,
0x50, 0x48, 0x88, 0x8b, 0xd1, 0x51, 0x82, 0x51, 0x81, 0x51, 0x83, 0xd3, 0x89, 0xe5, 0xc4, 0x3d,
0x79, 0x86, 0x20, 0x46, 0x47, 0x90, 0x98, 0x93, 0x04, 0x13, 0xb2, 0x98, 0x13, 0x48, 0xcc, 0x59,
0x82, 0x19, 0x59, 0xcc, 0x59, 0x49, 0x16, 0x6a, 0x4c, 0x71, 0x01, 0x36, 0x63, 0x9c, 0x4c, 0x4e,
0x3c, 0x94, 0x63, 0xb8, 0xf0, 0x50, 0x8e, 0xe1, 0xc6, 0x43, 0x39, 0x86, 0x07, 0x0f, 0xe5, 0x18,
0x3f, 0x3c, 0x94, 0x63, 0x6c, 0x78, 0x24, 0xc7, 0xb8, 0xe2, 0x91, 0x1c, 0xe3, 0x89, 0x47, 0x72,
0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0xf8, 0xe2, 0x91, 0x1c, 0xc3, 0x87, 0x47,
0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x00, 0x02, 0x00, 0x00, 0xff, 0xff, 0x40, 0xb0, 0x81, 0x16,
0xe8, 0x00, 0x00, 0x00,
}
syntax = "proto2";
package rpc_examples;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option (gogoproto.gostring_all) = true;
option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
// option (gogoproto.goproto_stringer_all) = false;
// option (gogoproto.stringer_all) = true;
// option (gogoproto.populate_all) = true;
// option (gogoproto.testgen_all) = true;
// option (gogoproto.benchgen_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.goproto_enum_prefix_all) = false;
//////////////////////////////////////////
// Request Header
//////////////////////////////////////////
message TestReq {
optional string A = 1 [(gogoproto.nullable) = false];
optional string B = 2 [(gogoproto.nullable) = false];
optional string C = 3 [(gogoproto.nullable) = false];
}
message TestRsp {
optional string A = 1 [(gogoproto.nullable) = false];
}
package rpc_examples
import (
"errors"
)
type TestService struct {
i int
}
func (r *TestService) Service() string {
return "TestService"
}
func (r *TestService) Version() string {
return "v1.0"
}
func (r *TestService) Test(arg TestReq, rsp *TestRsp) error {
rsp.A = arg.A + ", " + arg.B + ", " + arg.C
return nil
}
func (r *TestService) Add(n int, res *int) error {
r.i += n
*res = r.i + 100
return nil
}
func (r *TestService) Err(n int, res *int) error {
return errors.New("this is a error test")
}
package main
import (
"errors"
)
import (
log "github.com/AlexStocks/log4go"
)
type TestABC struct {
A, B, C string
}
type TestRpc struct {
i int
}
func (r *TestRpc) Service() string {
return "TestRpc"
}
func (r *TestRpc) Version() string {
return "v1.0"
}
func (r *TestRpc) Test(arg TestABC, res *string) error {
log.Debug("arg:%+v", arg)
*res = "this is a test"
return nil
}
func (r *TestRpc) Add(n int, res *int) error {
r.i += n
*res = r.i + 100
return nil
}
func (r *TestRpc) Err(n int, res *int) error {
return errors.New("this is a error test")
}
......@@ -19,6 +19,7 @@ import (
)
import (
"github.com/AlexStocks/getty-examples/rpc/proto"
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/log"
"github.com/AlexStocks/goext/net"
......@@ -68,7 +69,7 @@ func initServer() {
panic(jerrors.ErrorStack(err))
return
}
err = server.Register(new(TestRpc))
err = server.Register(&rpc_examples.TestService{})
if err != nil {
panic(jerrors.ErrorStack(err))
return
......
......@@ -29,5 +29,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-server"
......@@ -29,5 +29,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-server"
......@@ -29,5 +29,5 @@ FailFastTimeout = "3s"
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 128
MaxMsgLen = 1024
SessionName = "getty-rpc-server"
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