update tests and deps
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
60
client/drpc/drpc_test.go
Normal file
60
client/drpc/drpc_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// +build ignore
|
||||
|
||||
/*
|
||||
package drpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
drpc "github.com/unistack-org/micro-client-drpc/v3"
|
||||
protocodec "github.com/unistack-org/micro-codec-proto/v3"
|
||||
pb "github.com/unistack-org/micro-tests/client/drpc/proto"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"storj.io/drpc/drpcmux"
|
||||
"storj.io/drpc/drpcserver"
|
||||
)
|
||||
|
||||
type TestServer struct{}
|
||||
|
||||
func (s *TestServer) Call(ctx context.Context, req *pb.CallReq) (*pb.CallRsp, error) {
|
||||
return &pb.CallRsp{Name: req.Name + " rsp"}, nil
|
||||
}
|
||||
|
||||
func (s *TestServer) Hello(ctx context.Context, req *pb.CallReq) (*pb.CallRsp, error) {
|
||||
return &pb.CallRsp{Name: req.Name + " rsp"}, nil
|
||||
}
|
||||
|
||||
func TestDrpc(t *testing.T) {
|
||||
t.Skip()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
m := drpcmux.New()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
err = pb.DRPCRegisterTestService(m, &TestServer{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
if err := drpcserver.New(m).Serve(ctx, ln); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
c := client.NewClientCallOptions(drpc.NewClient(client.Codec("application/drpc+proto", protocodec.NewCodec())), client.WithAddress(ln.Addr().String()))
|
||||
cli := pb.NewTestServiceClient("test", c)
|
||||
rsp, err := cli.Call(ctx, &pb.CallReq{Name: "test_name"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rsp.Name != "test_name rsp" {
|
||||
t.Fatalf("unexpected rsp %#+v", rsp)
|
||||
}
|
||||
}
|
||||
*/
|
5
client/drpc/generate.go
Normal file
5
client/drpc/generate.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package drpc
|
||||
|
||||
//xxgo:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,debug=true,paths=source_relative:./proto proto/test.proto
|
||||
|
||||
//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,debug=true,paths=source_relative:./proto --go-drpc_out=json=false,paths=source_relative:./proto proto/test.proto
|
216
client/drpc/proto/test.pb.go
Normal file
216
client/drpc/proto/test.pb.go
Normal file
@@ -0,0 +1,216 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.15.6
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type CallReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CallReq) Reset() {
|
||||
*x = CallReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CallReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CallReq) ProtoMessage() {}
|
||||
|
||||
func (x *CallReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CallReq.ProtoReflect.Descriptor instead.
|
||||
func (*CallReq) Descriptor() ([]byte, []int) {
|
||||
return file_test_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *CallReq) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CallRsp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CallRsp) Reset() {
|
||||
*x = CallRsp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_test_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CallRsp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CallRsp) ProtoMessage() {}
|
||||
|
||||
func (x *CallRsp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_test_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CallRsp.ProtoReflect.Descriptor instead.
|
||||
func (*CallRsp) Descriptor() ([]byte, []int) {
|
||||
return file_test_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *CallRsp) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_test_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_test_proto_rawDesc = []byte{
|
||||
0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x54, 0x65,
|
||||
0x73, 0x74, 0x22, 0x1d, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
|
||||
0x65, 0x22, 0x1d, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x32, 0x5e, 0x0a, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
|
||||
0x26, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43,
|
||||
0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61,
|
||||
0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x27, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x12, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a,
|
||||
0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x00,
|
||||
0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75,
|
||||
0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72,
|
||||
0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x64,
|
||||
0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_test_proto_rawDescOnce sync.Once
|
||||
file_test_proto_rawDescData = file_test_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_test_proto_rawDescGZIP() []byte {
|
||||
file_test_proto_rawDescOnce.Do(func() {
|
||||
file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData)
|
||||
})
|
||||
return file_test_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_test_proto_goTypes = []interface{}{
|
||||
(*CallReq)(nil), // 0: Test.CallReq
|
||||
(*CallRsp)(nil), // 1: Test.CallRsp
|
||||
}
|
||||
var file_test_proto_depIdxs = []int32{
|
||||
0, // 0: Test.TestService.Call:input_type -> Test.CallReq
|
||||
0, // 1: Test.TestService.Hello:input_type -> Test.CallReq
|
||||
1, // 2: Test.TestService.Call:output_type -> Test.CallRsp
|
||||
1, // 3: Test.TestService.Hello:output_type -> Test.CallRsp
|
||||
2, // [2:4] is the sub-list for method output_type
|
||||
0, // [0:2] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_test_proto_init() }
|
||||
func file_test_proto_init() {
|
||||
if File_test_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CallReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CallRsp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_test_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_test_proto_goTypes,
|
||||
DependencyIndexes: file_test_proto_depIdxs,
|
||||
MessageInfos: file_test_proto_msgTypes,
|
||||
}.Build()
|
||||
File_test_proto = out.File
|
||||
file_test_proto_rawDesc = nil
|
||||
file_test_proto_goTypes = nil
|
||||
file_test_proto_depIdxs = nil
|
||||
}
|
18
client/drpc/proto/test.proto
Normal file
18
client/drpc/proto/test.proto
Normal file
@@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "github.com/unistack-org/micro-tests/client/drpc/proto;pb";
|
||||
|
||||
package Test;
|
||||
|
||||
service TestService {
|
||||
rpc Call(CallReq) returns (CallRsp) {}
|
||||
rpc Hello(CallReq) returns (CallRsp) {}
|
||||
}
|
||||
|
||||
message CallReq {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message CallRsp {
|
||||
string name = 1;
|
||||
}
|
142
client/drpc/proto/test_drpc.pb.go
Normal file
142
client/drpc/proto/test_drpc.pb.go
Normal file
@@ -0,0 +1,142 @@
|
||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||
// protoc-gen-go-drpc version: v0.0.23
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
errors "errors"
|
||||
proto "google.golang.org/protobuf/proto"
|
||||
drpc "storj.io/drpc"
|
||||
drpcerr "storj.io/drpc/drpcerr"
|
||||
)
|
||||
|
||||
type drpcEncoding_File_test_proto struct{}
|
||||
|
||||
func (drpcEncoding_File_test_proto) Marshal(msg drpc.Message) ([]byte, error) {
|
||||
return proto.Marshal(msg.(proto.Message))
|
||||
}
|
||||
|
||||
func (drpcEncoding_File_test_proto) MarshalAppend(buf []byte, msg drpc.Message) ([]byte, error) {
|
||||
return proto.MarshalOptions{}.MarshalAppend(buf, msg.(proto.Message))
|
||||
}
|
||||
|
||||
func (drpcEncoding_File_test_proto) Unmarshal(buf []byte, msg drpc.Message) error {
|
||||
return proto.Unmarshal(buf, msg.(proto.Message))
|
||||
}
|
||||
|
||||
type DRPCTestServiceClient interface {
|
||||
DRPCConn() drpc.Conn
|
||||
|
||||
Call(ctx context.Context, in *CallReq) (*CallRsp, error)
|
||||
Hello(ctx context.Context, in *CallReq) (*CallRsp, error)
|
||||
}
|
||||
|
||||
type drpcTestServiceClient struct {
|
||||
cc drpc.Conn
|
||||
}
|
||||
|
||||
func NewDRPCTestServiceClient(cc drpc.Conn) DRPCTestServiceClient {
|
||||
return &drpcTestServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *drpcTestServiceClient) DRPCConn() drpc.Conn { return c.cc }
|
||||
|
||||
func (c *drpcTestServiceClient) Call(ctx context.Context, in *CallReq) (*CallRsp, error) {
|
||||
out := new(CallRsp)
|
||||
err := c.cc.Invoke(ctx, "/Test.TestService/Call", drpcEncoding_File_test_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcTestServiceClient) Hello(ctx context.Context, in *CallReq) (*CallRsp, error) {
|
||||
out := new(CallRsp)
|
||||
err := c.cc.Invoke(ctx, "/Test.TestService/Hello", drpcEncoding_File_test_proto{}, in, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
type DRPCTestServiceServer interface {
|
||||
Call(context.Context, *CallReq) (*CallRsp, error)
|
||||
Hello(context.Context, *CallReq) (*CallRsp, error)
|
||||
}
|
||||
|
||||
type DRPCTestServiceUnimplementedServer struct{}
|
||||
|
||||
func (s *DRPCTestServiceUnimplementedServer) Call(context.Context, *CallReq) (*CallRsp, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), 12)
|
||||
}
|
||||
|
||||
func (s *DRPCTestServiceUnimplementedServer) Hello(context.Context, *CallReq) (*CallRsp, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), 12)
|
||||
}
|
||||
|
||||
type DRPCTestServiceDescription struct{}
|
||||
|
||||
func (DRPCTestServiceDescription) NumMethods() int { return 2 }
|
||||
|
||||
func (DRPCTestServiceDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||
switch n {
|
||||
case 0:
|
||||
return "/Test.TestService/Call", drpcEncoding_File_test_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCTestServiceServer).
|
||||
Call(
|
||||
ctx,
|
||||
in1.(*CallReq),
|
||||
)
|
||||
}, DRPCTestServiceServer.Call, true
|
||||
case 1:
|
||||
return "/Test.TestService/Hello", drpcEncoding_File_test_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCTestServiceServer).
|
||||
Hello(
|
||||
ctx,
|
||||
in1.(*CallReq),
|
||||
)
|
||||
}, DRPCTestServiceServer.Hello, true
|
||||
default:
|
||||
return "", nil, nil, nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func DRPCRegisterTestService(mux drpc.Mux, impl DRPCTestServiceServer) error {
|
||||
return mux.Register(impl, DRPCTestServiceDescription{})
|
||||
}
|
||||
|
||||
type DRPCTestService_CallStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*CallRsp) error
|
||||
}
|
||||
|
||||
type drpcTestService_CallStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcTestService_CallStream) SendAndClose(m *CallRsp) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_test_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCTestService_HelloStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*CallRsp) error
|
||||
}
|
||||
|
||||
type drpcTestService_HelloStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcTestService_HelloStream) SendAndClose(m *CallRsp) error {
|
||||
if err := x.MsgSend(m, drpcEncoding_File_test_proto{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return x.CloseSend()
|
||||
}
|
29
client/drpc/proto/test_micro.pb.go
Normal file
29
client/drpc/proto/test_micro.pb.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.4.0
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
client "github.com/unistack-org/micro/v3/client"
|
||||
)
|
||||
|
||||
var (
|
||||
TestServiceEndpoints = []api.Endpoint{}
|
||||
)
|
||||
|
||||
func NewTestServiceEndpoints() []api.Endpoint {
|
||||
return TestServiceEndpoints
|
||||
}
|
||||
|
||||
type TestServiceClient interface {
|
||||
Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
|
||||
Hello(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
|
||||
}
|
||||
|
||||
type TestServiceServer interface {
|
||||
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||
Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||
}
|
67
client/drpc/proto/test_micro_rpc.pb.go
Normal file
67
client/drpc/proto/test_micro_rpc.pb.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.4.0
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
client "github.com/unistack-org/micro/v3/client"
|
||||
server "github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
|
||||
type testServiceClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewTestServiceClient(name string, c client.Client) TestServiceClient {
|
||||
return &testServiceClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *testServiceClient) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
|
||||
rsp := &CallRsp{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.Call", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
func (c *testServiceClient) Hello(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
|
||||
rsp := &CallRsp{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.Hello", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
type testServiceServer struct {
|
||||
TestServiceServer
|
||||
}
|
||||
|
||||
func (h *testServiceServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error {
|
||||
return h.TestServiceServer.Call(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func (h *testServiceServer) Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error {
|
||||
return h.TestServiceServer.Hello(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func RegisterTestServiceServer(s server.Server, sh TestServiceServer, opts ...server.HandlerOption) error {
|
||||
type testService interface {
|
||||
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||
Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||
}
|
||||
type TestService struct {
|
||||
testService
|
||||
}
|
||||
h := &testServiceServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
for _, endpoint := range TestServiceEndpoints {
|
||||
nopts = append(nopts, api.WithEndpoint(&endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&TestService{h}, append(nopts, opts...)...))
|
||||
}
|
7
client/drpc/tools.go
Normal file
7
client/drpc/tools.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// +build tools
|
||||
|
||||
package drpc
|
||||
|
||||
import (
|
||||
_ "storj.io/drpc/cmd/protoc-gen-go-drpc"
|
||||
)
|
@@ -50,13 +50,14 @@ func TestError(t *testing.T) {
|
||||
c := client.NewClientCallOptions(mhttp.NewClient(client.ContentType("application/json"), client.Codec("application/json", jsoncodec.NewCodec())), client.WithAddress("https://api.github.com"))
|
||||
req := c.NewRequest("github", "/dddd", &pb.LookupUserReq{})
|
||||
rsp := &GithubRsp{}
|
||||
errMap := map[string]interface{}{"404": &GithubRspError{}}
|
||||
err := c.Call(context.TODO(), req, rsp, mhttp.Method(http.MethodGet), mhttp.ErrorMap(errMap))
|
||||
errMap := map[string]interface{}{"404": &pb.Error{}}
|
||||
err := mhttp.GetError(c.Call(context.TODO(), req, rsp, mhttp.Method(http.MethodGet), mhttp.ErrorMap(errMap)))
|
||||
if err == nil {
|
||||
t.Fatal("request must return non nil err")
|
||||
}
|
||||
if _, ok := err.(*GithubRspError); !ok {
|
||||
t.Fatalf("invalid response received: %T is not *GithubRspError type: %#+v", err, err)
|
||||
|
||||
if _, ok := err.(*pb.Error); !ok {
|
||||
t.Fatalf("invalid response received: %T is not *pb.Error type: %#+v", err, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -121,7 +121,8 @@ type Error struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
DocumentationUrl string `protobuf:"bytes,2,opt,name=documentation_url,json=documentationUrl,proto3" json:"documentation_url,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Error) Reset() {
|
||||
@@ -163,6 +164,13 @@ func (x *Error) GetMessage() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Error) GetDocumentationUrl() string {
|
||||
if x != nil {
|
||||
return x.DocumentationUrl
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_github_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_github_proto_rawDesc = []byte{
|
||||
@@ -175,34 +183,37 @@ var file_github_proto_rawDesc = []byte{
|
||||
0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75,
|
||||
0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x23, 0x0a, 0x0d, 0x4c, 0x6f, 0x6f, 0x6b, 0x75,
|
||||
0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x21, 0x0a, 0x05,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x4e, 0x0a, 0x05,
|
||||
0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32,
|
||||
0xc6, 0x02, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x68, 0x75, 0x62, 0x12, 0x94, 0x01, 0x0a, 0x0a, 0x4c,
|
||||
0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x12, 0x15, 0x2e, 0x67, 0x69, 0x74, 0x68,
|
||||
0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71,
|
||||
0x1a, 0x15, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70,
|
||||
0x55, 0x73, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x58, 0x92, 0x41, 0x3c, 0x2a, 0x0a, 0x4c, 0x6f,
|
||||
0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x4a, 0x2e, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61,
|
||||
0x75, 0x6c, 0x74, 0x12, 0x23, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x11, 0x0a, 0x0f, 0x1a, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x68,
|
||||
0x75, 0x62, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11,
|
||||
0x2f, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2f, 0x7b, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x7d, 0x12, 0xa4, 0x01, 0x0a, 0x15, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72,
|
||||
0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x61, 0x74, 0x68, 0x12, 0x15, 0x2e, 0x67, 0x69,
|
||||
0x74, 0x68, 0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52,
|
||||
0x65, 0x71, 0x1a, 0x15, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b,
|
||||
0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x5d, 0x92, 0x41, 0x47, 0x2a, 0x15,
|
||||
0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75,
|
||||
0x74, 0x50, 0x61, 0x74, 0x68, 0x4a, 0x2e, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12,
|
||||
0x2b, 0x0a, 0x11, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x5f, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x64, 0x6f, 0x63, 0x75,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x72, 0x6c, 0x32, 0xc6, 0x02, 0x0a,
|
||||
0x06, 0x47, 0x69, 0x74, 0x68, 0x75, 0x62, 0x12, 0x94, 0x01, 0x0a, 0x0a, 0x4c, 0x6f, 0x6f, 0x6b,
|
||||
0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x12, 0x15, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
||||
0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e,
|
||||
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65,
|
||||
0x72, 0x52, 0x73, 0x70, 0x22, 0x58, 0x92, 0x41, 0x3c, 0x2a, 0x0a, 0x4c, 0x6f, 0x6f, 0x6b, 0x75,
|
||||
0x70, 0x55, 0x73, 0x65, 0x72, 0x4a, 0x2e, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
|
||||
0x12, 0x23, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x12, 0x11, 0x0a, 0x0f, 0x1a, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
||||
0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x7b, 0x75,
|
||||
0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68,
|
||||
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b,
|
||||
0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73,
|
||||
0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x75, 0x73,
|
||||
0x65, 0x72, 0x73, 0x2f, 0x7b, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x12, 0xa4,
|
||||
0x01, 0x0a, 0x15, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x57, 0x69, 0x74,
|
||||
0x68, 0x6f, 0x75, 0x74, 0x50, 0x61, 0x74, 0x68, 0x12, 0x15, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75,
|
||||
0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a,
|
||||
0x15, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x55,
|
||||
0x73, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x5d, 0x92, 0x41, 0x47, 0x2a, 0x15, 0x4c, 0x6f, 0x6f,
|
||||
0x6b, 0x75, 0x70, 0x55, 0x73, 0x65, 0x72, 0x57, 0x69, 0x74, 0x68, 0x6f, 0x75, 0x74, 0x50, 0x61,
|
||||
0x74, 0x68, 0x4a, 0x2e, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x23, 0x0a,
|
||||
0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x11, 0x0a, 0x0f, 0x1a, 0x0d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x45, 0x72, 0x72,
|
||||
0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x7b, 0x75, 0x73, 0x65, 0x72,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
||||
0x63, 0x6f, 0x6d, 0x2f, 0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72,
|
||||
0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x63, 0x6c,
|
||||
0x69, 0x65, 0x6e, 0x74, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b,
|
||||
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@@ -46,5 +46,6 @@ message LookupUserRsp {
|
||||
|
||||
message Error {
|
||||
string message = 1;
|
||||
string documentation_url = 2;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user