Merge pull request #116 from dmcgowan/service-prefix
Add service prefix option to generator
This commit is contained in:
commit
0ac5158442
4
Makefile
4
Makefile
@ -145,8 +145,8 @@ install-protobuf:
|
||||
|
||||
install-protobuild:
|
||||
@echo "$(WHALE) $@"
|
||||
@$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
|
||||
@$(GO) install github.com/containerd/protobuild@7e5ee24bc1f70e9e289fef15e2631eb3491320bf
|
||||
@$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
|
||||
@$(GO) install github.com/containerd/protobuild@14832ccc41429f5c4f81028e5af08aa233a219cf
|
||||
|
||||
coverage: ## generate coverprofiles from the unit tests, except tests that require root
|
||||
@echo "$(WHALE) $@"
|
||||
|
@ -23,3 +23,6 @@ generators = ["go"]
|
||||
# enable ttrpc and disable fieldpath and grpc for the shim
|
||||
prefixes = ["github.com/containerd/ttrpc/integration/streaming"]
|
||||
generators = ["go", "go-ttrpc"]
|
||||
|
||||
[overrides.parameters.go-ttrpc]
|
||||
prefix = "TTRPC"
|
||||
|
@ -90,7 +90,7 @@ func newGenerator(out *protogen.GeneratedFile) *generator {
|
||||
return &gen
|
||||
}
|
||||
|
||||
func generate(plugin *protogen.Plugin, input *protogen.File) error {
|
||||
func generate(plugin *protogen.Plugin, input *protogen.File, servicePrefix string) error {
|
||||
if len(input.Services) == 0 {
|
||||
// Only generate a Go file if the file has some services.
|
||||
return nil
|
||||
@ -103,6 +103,7 @@ func generate(plugin *protogen.Plugin, input *protogen.File) error {
|
||||
|
||||
gen := newGenerator(file)
|
||||
for _, service := range input.Services {
|
||||
service.GoName = servicePrefix + service.GoName
|
||||
gen.genService(service)
|
||||
}
|
||||
return nil
|
||||
@ -266,7 +267,7 @@ func (gen *generator) genService(service *protogen.Service) {
|
||||
p.P()
|
||||
}
|
||||
|
||||
clientStructType := strings.ToLower(clientType[:1]) + clientType[1:]
|
||||
clientStructType := strings.ToLower(service.GoName) + "Client"
|
||||
p.P("type ", clientStructType, " struct{")
|
||||
p.P("client *", gen.ident.client)
|
||||
p.P("}")
|
||||
|
@ -21,12 +21,20 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
|
||||
var servicePrefix string
|
||||
protogen.Options{
|
||||
ParamFunc: func(name, value string) error {
|
||||
if name == "prefix" {
|
||||
servicePrefix = value
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}.Run(func(gen *protogen.Plugin) error {
|
||||
for _, f := range gen.Files {
|
||||
if !f.Generate {
|
||||
continue
|
||||
}
|
||||
if err := generate(gen, f); err != nil {
|
||||
if err := generate(gen, f, servicePrefix); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,16 @@
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.11.4
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.20.1
|
||||
// source: github.com/containerd/ttrpc/integration/streaming/test.proto
|
||||
|
||||
package streaming
|
||||
|
||||
import (
|
||||
empty "github.com/golang/protobuf/ptypes/empty"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
@ -266,10 +266,10 @@ func file_github_com_containerd_ttrpc_integration_streaming_test_proto_rawDescGZ
|
||||
|
||||
var file_github_com_containerd_ttrpc_integration_streaming_test_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_github_com_containerd_ttrpc_integration_streaming_test_proto_goTypes = []interface{}{
|
||||
(*EchoPayload)(nil), // 0: ttrpc.integration.streaming.EchoPayload
|
||||
(*Part)(nil), // 1: ttrpc.integration.streaming.Part
|
||||
(*Sum)(nil), // 2: ttrpc.integration.streaming.Sum
|
||||
(*empty.Empty)(nil), // 3: google.protobuf.Empty
|
||||
(*EchoPayload)(nil), // 0: ttrpc.integration.streaming.EchoPayload
|
||||
(*Part)(nil), // 1: ttrpc.integration.streaming.Part
|
||||
(*Sum)(nil), // 2: ttrpc.integration.streaming.Sum
|
||||
(*emptypb.Empty)(nil), // 3: google.protobuf.Empty
|
||||
}
|
||||
var file_github_com_containerd_ttrpc_integration_streaming_test_proto_depIdxs = []int32{
|
||||
0, // 0: ttrpc.integration.streaming.Streaming.Echo:input_type -> ttrpc.integration.streaming.EchoPayload
|
||||
|
@ -5,33 +5,33 @@ package streaming
|
||||
import (
|
||||
context "context"
|
||||
ttrpc "github.com/containerd/ttrpc"
|
||||
empty "github.com/golang/protobuf/ptypes/empty"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type StreamingService interface {
|
||||
type TTRPCStreamingService interface {
|
||||
Echo(context.Context, *EchoPayload) (*EchoPayload, error)
|
||||
EchoStream(context.Context, Streaming_EchoStreamServer) error
|
||||
SumStream(context.Context, Streaming_SumStreamServer) (*Sum, error)
|
||||
DivideStream(context.Context, *Sum, Streaming_DivideStreamServer) error
|
||||
EchoNull(context.Context, Streaming_EchoNullServer) (*empty.Empty, error)
|
||||
EchoNullStream(context.Context, Streaming_EchoNullStreamServer) error
|
||||
EchoStream(context.Context, TTRPCStreaming_EchoStreamServer) error
|
||||
SumStream(context.Context, TTRPCStreaming_SumStreamServer) (*Sum, error)
|
||||
DivideStream(context.Context, *Sum, TTRPCStreaming_DivideStreamServer) error
|
||||
EchoNull(context.Context, TTRPCStreaming_EchoNullServer) (*emptypb.Empty, error)
|
||||
EchoNullStream(context.Context, TTRPCStreaming_EchoNullStreamServer) error
|
||||
}
|
||||
|
||||
type Streaming_EchoStreamServer interface {
|
||||
type TTRPCStreaming_EchoStreamServer interface {
|
||||
Send(*EchoPayload) error
|
||||
Recv() (*EchoPayload, error)
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
type streamingEchoStreamServer struct {
|
||||
type ttrpcstreamingEchoStreamServer struct {
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
func (x *streamingEchoStreamServer) Send(m *EchoPayload) error {
|
||||
func (x *ttrpcstreamingEchoStreamServer) Send(m *EchoPayload) error {
|
||||
return x.StreamServer.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingEchoStreamServer) Recv() (*EchoPayload, error) {
|
||||
func (x *ttrpcstreamingEchoStreamServer) Recv() (*EchoPayload, error) {
|
||||
m := new(EchoPayload)
|
||||
if err := x.StreamServer.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -39,16 +39,16 @@ func (x *streamingEchoStreamServer) Recv() (*EchoPayload, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
type Streaming_SumStreamServer interface {
|
||||
type TTRPCStreaming_SumStreamServer interface {
|
||||
Recv() (*Part, error)
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
type streamingSumStreamServer struct {
|
||||
type ttrpcstreamingSumStreamServer struct {
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
func (x *streamingSumStreamServer) Recv() (*Part, error) {
|
||||
func (x *ttrpcstreamingSumStreamServer) Recv() (*Part, error) {
|
||||
m := new(Part)
|
||||
if err := x.StreamServer.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -56,29 +56,29 @@ func (x *streamingSumStreamServer) Recv() (*Part, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
type Streaming_DivideStreamServer interface {
|
||||
type TTRPCStreaming_DivideStreamServer interface {
|
||||
Send(*Part) error
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
type streamingDivideStreamServer struct {
|
||||
type ttrpcstreamingDivideStreamServer struct {
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
func (x *streamingDivideStreamServer) Send(m *Part) error {
|
||||
func (x *ttrpcstreamingDivideStreamServer) Send(m *Part) error {
|
||||
return x.StreamServer.SendMsg(m)
|
||||
}
|
||||
|
||||
type Streaming_EchoNullServer interface {
|
||||
type TTRPCStreaming_EchoNullServer interface {
|
||||
Recv() (*EchoPayload, error)
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
type streamingEchoNullServer struct {
|
||||
type ttrpcstreamingEchoNullServer struct {
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullServer) Recv() (*EchoPayload, error) {
|
||||
func (x *ttrpcstreamingEchoNullServer) Recv() (*EchoPayload, error) {
|
||||
m := new(EchoPayload)
|
||||
if err := x.StreamServer.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -86,21 +86,21 @@ func (x *streamingEchoNullServer) Recv() (*EchoPayload, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
type Streaming_EchoNullStreamServer interface {
|
||||
Send(*empty.Empty) error
|
||||
type TTRPCStreaming_EchoNullStreamServer interface {
|
||||
Send(*emptypb.Empty) error
|
||||
Recv() (*EchoPayload, error)
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
type streamingEchoNullStreamServer struct {
|
||||
type ttrpcstreamingEchoNullStreamServer struct {
|
||||
ttrpc.StreamServer
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullStreamServer) Send(m *empty.Empty) error {
|
||||
func (x *ttrpcstreamingEchoNullStreamServer) Send(m *emptypb.Empty) error {
|
||||
return x.StreamServer.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullStreamServer) Recv() (*EchoPayload, error) {
|
||||
func (x *ttrpcstreamingEchoNullStreamServer) Recv() (*EchoPayload, error) {
|
||||
m := new(EchoPayload)
|
||||
if err := x.StreamServer.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -108,7 +108,7 @@ func (x *streamingEchoNullStreamServer) Recv() (*EchoPayload, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func RegisterStreamingService(srv *ttrpc.Server, svc StreamingService) {
|
||||
func RegisterTTRPCStreamingService(srv *ttrpc.Server, svc TTRPCStreamingService) {
|
||||
srv.RegisterService("ttrpc.integration.streaming.Streaming", &ttrpc.ServiceDesc{
|
||||
Methods: map[string]ttrpc.Method{
|
||||
"Echo": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
|
||||
@ -122,14 +122,14 @@ func RegisterStreamingService(srv *ttrpc.Server, svc StreamingService) {
|
||||
Streams: map[string]ttrpc.Stream{
|
||||
"EchoStream": {
|
||||
Handler: func(ctx context.Context, stream ttrpc.StreamServer) (interface{}, error) {
|
||||
return nil, svc.EchoStream(ctx, &streamingEchoStreamServer{stream})
|
||||
return nil, svc.EchoStream(ctx, &ttrpcstreamingEchoStreamServer{stream})
|
||||
},
|
||||
StreamingClient: true,
|
||||
StreamingServer: true,
|
||||
},
|
||||
"SumStream": {
|
||||
Handler: func(ctx context.Context, stream ttrpc.StreamServer) (interface{}, error) {
|
||||
return svc.SumStream(ctx, &streamingSumStreamServer{stream})
|
||||
return svc.SumStream(ctx, &ttrpcstreamingSumStreamServer{stream})
|
||||
},
|
||||
StreamingClient: true,
|
||||
StreamingServer: false,
|
||||
@ -140,21 +140,21 @@ func RegisterStreamingService(srv *ttrpc.Server, svc StreamingService) {
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, svc.DivideStream(ctx, m, &streamingDivideStreamServer{stream})
|
||||
return nil, svc.DivideStream(ctx, m, &ttrpcstreamingDivideStreamServer{stream})
|
||||
},
|
||||
StreamingClient: false,
|
||||
StreamingServer: true,
|
||||
},
|
||||
"EchoNull": {
|
||||
Handler: func(ctx context.Context, stream ttrpc.StreamServer) (interface{}, error) {
|
||||
return svc.EchoNull(ctx, &streamingEchoNullServer{stream})
|
||||
return svc.EchoNull(ctx, &ttrpcstreamingEchoNullServer{stream})
|
||||
},
|
||||
StreamingClient: true,
|
||||
StreamingServer: false,
|
||||
},
|
||||
"EchoNullStream": {
|
||||
Handler: func(ctx context.Context, stream ttrpc.StreamServer) (interface{}, error) {
|
||||
return nil, svc.EchoNullStream(ctx, &streamingEchoNullStreamServer{stream})
|
||||
return nil, svc.EchoNullStream(ctx, &ttrpcstreamingEchoNullStreamServer{stream})
|
||||
},
|
||||
StreamingClient: true,
|
||||
StreamingServer: true,
|
||||
@ -163,26 +163,26 @@ func RegisterStreamingService(srv *ttrpc.Server, svc StreamingService) {
|
||||
})
|
||||
}
|
||||
|
||||
type StreamingClient interface {
|
||||
type TTRPCStreamingClient interface {
|
||||
Echo(context.Context, *EchoPayload) (*EchoPayload, error)
|
||||
EchoStream(context.Context) (Streaming_EchoStreamClient, error)
|
||||
SumStream(context.Context) (Streaming_SumStreamClient, error)
|
||||
DivideStream(context.Context, *Sum) (Streaming_DivideStreamClient, error)
|
||||
EchoNull(context.Context) (Streaming_EchoNullClient, error)
|
||||
EchoNullStream(context.Context) (Streaming_EchoNullStreamClient, error)
|
||||
EchoStream(context.Context) (TTRPCStreaming_EchoStreamClient, error)
|
||||
SumStream(context.Context) (TTRPCStreaming_SumStreamClient, error)
|
||||
DivideStream(context.Context, *Sum) (TTRPCStreaming_DivideStreamClient, error)
|
||||
EchoNull(context.Context) (TTRPCStreaming_EchoNullClient, error)
|
||||
EchoNullStream(context.Context) (TTRPCStreaming_EchoNullStreamClient, error)
|
||||
}
|
||||
|
||||
type streamingClient struct {
|
||||
type ttrpcstreamingClient struct {
|
||||
client *ttrpc.Client
|
||||
}
|
||||
|
||||
func NewStreamingClient(client *ttrpc.Client) StreamingClient {
|
||||
return &streamingClient{
|
||||
func NewTTRPCStreamingClient(client *ttrpc.Client) TTRPCStreamingClient {
|
||||
return &ttrpcstreamingClient{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *streamingClient) Echo(ctx context.Context, req *EchoPayload) (*EchoPayload, error) {
|
||||
func (c *ttrpcstreamingClient) Echo(ctx context.Context, req *EchoPayload) (*EchoPayload, error) {
|
||||
var resp EchoPayload
|
||||
if err := c.client.Call(ctx, "ttrpc.integration.streaming.Streaming", "Echo", req, &resp); err != nil {
|
||||
return nil, err
|
||||
@ -190,7 +190,7 @@ func (c *streamingClient) Echo(ctx context.Context, req *EchoPayload) (*EchoPayl
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (c *streamingClient) EchoStream(ctx context.Context) (Streaming_EchoStreamClient, error) {
|
||||
func (c *ttrpcstreamingClient) EchoStream(ctx context.Context) (TTRPCStreaming_EchoStreamClient, error) {
|
||||
stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
|
||||
StreamingClient: true,
|
||||
StreamingServer: true,
|
||||
@ -198,25 +198,25 @@ func (c *streamingClient) EchoStream(ctx context.Context) (Streaming_EchoStreamC
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &streamingEchoStreamClient{stream}
|
||||
x := &ttrpcstreamingEchoStreamClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Streaming_EchoStreamClient interface {
|
||||
type TTRPCStreaming_EchoStreamClient interface {
|
||||
Send(*EchoPayload) error
|
||||
Recv() (*EchoPayload, error)
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
type streamingEchoStreamClient struct {
|
||||
type ttrpcstreamingEchoStreamClient struct {
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *streamingEchoStreamClient) Send(m *EchoPayload) error {
|
||||
func (x *ttrpcstreamingEchoStreamClient) Send(m *EchoPayload) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingEchoStreamClient) Recv() (*EchoPayload, error) {
|
||||
func (x *ttrpcstreamingEchoStreamClient) Recv() (*EchoPayload, error) {
|
||||
m := new(EchoPayload)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -224,7 +224,7 @@ func (x *streamingEchoStreamClient) Recv() (*EchoPayload, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *streamingClient) SumStream(ctx context.Context) (Streaming_SumStreamClient, error) {
|
||||
func (c *ttrpcstreamingClient) SumStream(ctx context.Context) (TTRPCStreaming_SumStreamClient, error) {
|
||||
stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
|
||||
StreamingClient: true,
|
||||
StreamingServer: false,
|
||||
@ -232,25 +232,25 @@ func (c *streamingClient) SumStream(ctx context.Context) (Streaming_SumStreamCli
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &streamingSumStreamClient{stream}
|
||||
x := &ttrpcstreamingSumStreamClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Streaming_SumStreamClient interface {
|
||||
type TTRPCStreaming_SumStreamClient interface {
|
||||
Send(*Part) error
|
||||
CloseAndRecv() (*Sum, error)
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
type streamingSumStreamClient struct {
|
||||
type ttrpcstreamingSumStreamClient struct {
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *streamingSumStreamClient) Send(m *Part) error {
|
||||
func (x *ttrpcstreamingSumStreamClient) Send(m *Part) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingSumStreamClient) CloseAndRecv() (*Sum, error) {
|
||||
func (x *ttrpcstreamingSumStreamClient) CloseAndRecv() (*Sum, error) {
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -261,7 +261,7 @@ func (x *streamingSumStreamClient) CloseAndRecv() (*Sum, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *streamingClient) DivideStream(ctx context.Context, req *Sum) (Streaming_DivideStreamClient, error) {
|
||||
func (c *ttrpcstreamingClient) DivideStream(ctx context.Context, req *Sum) (TTRPCStreaming_DivideStreamClient, error) {
|
||||
stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
|
||||
StreamingClient: false,
|
||||
StreamingServer: true,
|
||||
@ -269,20 +269,20 @@ func (c *streamingClient) DivideStream(ctx context.Context, req *Sum) (Streaming
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &streamingDivideStreamClient{stream}
|
||||
x := &ttrpcstreamingDivideStreamClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Streaming_DivideStreamClient interface {
|
||||
type TTRPCStreaming_DivideStreamClient interface {
|
||||
Recv() (*Part, error)
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
type streamingDivideStreamClient struct {
|
||||
type ttrpcstreamingDivideStreamClient struct {
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *streamingDivideStreamClient) Recv() (*Part, error) {
|
||||
func (x *ttrpcstreamingDivideStreamClient) Recv() (*Part, error) {
|
||||
m := new(Part)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -290,7 +290,7 @@ func (x *streamingDivideStreamClient) Recv() (*Part, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *streamingClient) EchoNull(ctx context.Context) (Streaming_EchoNullClient, error) {
|
||||
func (c *ttrpcstreamingClient) EchoNull(ctx context.Context) (TTRPCStreaming_EchoNullClient, error) {
|
||||
stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
|
||||
StreamingClient: true,
|
||||
StreamingServer: false,
|
||||
@ -298,36 +298,36 @@ func (c *streamingClient) EchoNull(ctx context.Context) (Streaming_EchoNullClien
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &streamingEchoNullClient{stream}
|
||||
x := &ttrpcstreamingEchoNullClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Streaming_EchoNullClient interface {
|
||||
type TTRPCStreaming_EchoNullClient interface {
|
||||
Send(*EchoPayload) error
|
||||
CloseAndRecv() (*empty.Empty, error)
|
||||
CloseAndRecv() (*emptypb.Empty, error)
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
type streamingEchoNullClient struct {
|
||||
type ttrpcstreamingEchoNullClient struct {
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullClient) Send(m *EchoPayload) error {
|
||||
func (x *ttrpcstreamingEchoNullClient) Send(m *EchoPayload) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullClient) CloseAndRecv() (*empty.Empty, error) {
|
||||
func (x *ttrpcstreamingEchoNullClient) CloseAndRecv() (*emptypb.Empty, error) {
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m := new(empty.Empty)
|
||||
m := new(emptypb.Empty)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *streamingClient) EchoNullStream(ctx context.Context) (Streaming_EchoNullStreamClient, error) {
|
||||
func (c *ttrpcstreamingClient) EchoNullStream(ctx context.Context) (TTRPCStreaming_EchoNullStreamClient, error) {
|
||||
stream, err := c.client.NewStream(ctx, &ttrpc.StreamDesc{
|
||||
StreamingClient: true,
|
||||
StreamingServer: true,
|
||||
@ -335,26 +335,26 @@ func (c *streamingClient) EchoNullStream(ctx context.Context) (Streaming_EchoNul
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &streamingEchoNullStreamClient{stream}
|
||||
x := &ttrpcstreamingEchoNullStreamClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Streaming_EchoNullStreamClient interface {
|
||||
type TTRPCStreaming_EchoNullStreamClient interface {
|
||||
Send(*EchoPayload) error
|
||||
Recv() (*empty.Empty, error)
|
||||
Recv() (*emptypb.Empty, error)
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
type streamingEchoNullStreamClient struct {
|
||||
type ttrpcstreamingEchoNullStreamClient struct {
|
||||
ttrpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullStreamClient) Send(m *EchoPayload) error {
|
||||
func (x *ttrpcstreamingEchoNullStreamClient) Send(m *EchoPayload) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *streamingEchoNullStreamClient) Recv() (*empty.Empty, error) {
|
||||
m := new(empty.Empty)
|
||||
func (x *ttrpcstreamingEchoNullStreamClient) Recv() (*emptypb.Empty, error) {
|
||||
m := new(emptypb.Empty)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -33,13 +33,13 @@ import (
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
)
|
||||
|
||||
func runService(ctx context.Context, t testing.TB, service streaming.StreamingService) (streaming.StreamingClient, func()) {
|
||||
func runService(ctx context.Context, t testing.TB, service streaming.TTRPCStreamingService) (streaming.TTRPCStreamingClient, func()) {
|
||||
server, err := ttrpc.NewServer()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
streaming.RegisterStreamingService(server, service)
|
||||
streaming.RegisterTTRPCStreamingService(server, service)
|
||||
|
||||
addr := t.Name() + ".sock"
|
||||
if err := os.RemoveAll(addr); err != nil {
|
||||
@ -71,7 +71,7 @@ func runService(ctx context.Context, t testing.TB, service streaming.StreamingSe
|
||||
}
|
||||
|
||||
client := ttrpc.NewClient(conn)
|
||||
return streaming.NewStreamingClient(client), func() {
|
||||
return streaming.NewTTRPCStreamingClient(client), func() {
|
||||
client.Close()
|
||||
server.Close()
|
||||
conn.Close()
|
||||
@ -88,7 +88,7 @@ func (tss *testStreamingService) Echo(_ context.Context, e *streaming.EchoPayloa
|
||||
return e, nil
|
||||
}
|
||||
|
||||
func (tss *testStreamingService) EchoStream(_ context.Context, es streaming.Streaming_EchoStreamServer) error {
|
||||
func (tss *testStreamingService) EchoStream(_ context.Context, es streaming.TTRPCStreaming_EchoStreamServer) error {
|
||||
for {
|
||||
var e streaming.EchoPayload
|
||||
if err := es.RecvMsg(&e); err != nil {
|
||||
@ -105,7 +105,7 @@ func (tss *testStreamingService) EchoStream(_ context.Context, es streaming.Stre
|
||||
}
|
||||
}
|
||||
|
||||
func (tss *testStreamingService) SumStream(_ context.Context, ss streaming.Streaming_SumStreamServer) (*streaming.Sum, error) {
|
||||
func (tss *testStreamingService) SumStream(_ context.Context, ss streaming.TTRPCStreaming_SumStreamServer) (*streaming.Sum, error) {
|
||||
var sum streaming.Sum
|
||||
for {
|
||||
var part streaming.Part
|
||||
@ -122,7 +122,7 @@ func (tss *testStreamingService) SumStream(_ context.Context, ss streaming.Strea
|
||||
return &sum, nil
|
||||
}
|
||||
|
||||
func (tss *testStreamingService) DivideStream(_ context.Context, sum *streaming.Sum, ss streaming.Streaming_DivideStreamServer) error {
|
||||
func (tss *testStreamingService) DivideStream(_ context.Context, sum *streaming.Sum, ss streaming.TTRPCStreaming_DivideStreamServer) error {
|
||||
parts := divideSum(sum)
|
||||
for _, part := range parts {
|
||||
if err := ss.Send(part); err != nil {
|
||||
@ -131,7 +131,7 @@ func (tss *testStreamingService) DivideStream(_ context.Context, sum *streaming.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (tss *testStreamingService) EchoNull(_ context.Context, es streaming.Streaming_EchoNullServer) (*empty.Empty, error) {
|
||||
func (tss *testStreamingService) EchoNull(_ context.Context, es streaming.TTRPCStreaming_EchoNullServer) (*empty.Empty, error) {
|
||||
msg := "non-empty empty"
|
||||
for seq := uint32(0); ; seq++ {
|
||||
var e streaming.EchoPayload
|
||||
@ -152,7 +152,7 @@ func (tss *testStreamingService) EchoNull(_ context.Context, es streaming.Stream
|
||||
return &empty.Empty{}, nil
|
||||
}
|
||||
|
||||
func (tss *testStreamingService) EchoNullStream(_ context.Context, es streaming.Streaming_EchoNullStreamServer) error {
|
||||
func (tss *testStreamingService) EchoNullStream(_ context.Context, es streaming.TTRPCStreaming_EchoNullStreamServer) error {
|
||||
msg := "non-empty empty"
|
||||
empty := &empty.Empty{}
|
||||
var wg sync.WaitGroup
|
||||
@ -205,7 +205,7 @@ func TestStreamingService(t *testing.T) {
|
||||
t.Run("EchoNullStream", echoNullStreamTest(ctx, client))
|
||||
}
|
||||
|
||||
func echoTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func echoTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
echo1 := &streaming.EchoPayload{
|
||||
Seq: 1,
|
||||
@ -220,7 +220,7 @@ func echoTest(ctx context.Context, client streaming.StreamingClient) func(t *tes
|
||||
|
||||
}
|
||||
|
||||
func echoStreamTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func echoStreamTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
stream, err := client.EchoStream(ctx)
|
||||
if err != nil {
|
||||
@ -251,7 +251,7 @@ func echoStreamTest(ctx context.Context, client streaming.StreamingClient) func(
|
||||
}
|
||||
}
|
||||
|
||||
func sumStreamTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func sumStreamTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
stream, err := client.SumStream(ctx)
|
||||
if err != nil {
|
||||
@ -285,7 +285,7 @@ func sumStreamTest(ctx context.Context, client streaming.StreamingClient) func(t
|
||||
}
|
||||
}
|
||||
|
||||
func divideStreamTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func divideStreamTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
expected := &streaming.Sum{
|
||||
Sum: 392,
|
||||
@ -312,7 +312,7 @@ func divideStreamTest(ctx context.Context, client streaming.StreamingClient) fun
|
||||
assertSum(t, &actual, expected)
|
||||
}
|
||||
}
|
||||
func echoNullTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func echoNullTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
stream, err := client.EchoNull(ctx)
|
||||
if err != nil {
|
||||
@ -334,7 +334,7 @@ func echoNullTest(ctx context.Context, client streaming.StreamingClient) func(t
|
||||
|
||||
}
|
||||
}
|
||||
func echoNullStreamTest(ctx context.Context, client streaming.StreamingClient) func(t *testing.T) {
|
||||
func echoNullStreamTest(ctx context.Context, client streaming.TTRPCStreamingClient) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
stream, err := client.EchoNullStream(ctx)
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.11.4
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.20.1
|
||||
// source: github.com/containerd/ttrpc/test.proto
|
||||
|
||||
package internal
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.27.1
|
||||
// protoc v3.11.4
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.20.1
|
||||
// source: github.com/containerd/ttrpc/request.proto
|
||||
|
||||
package ttrpc
|
||||
|
@ -20,7 +20,7 @@
|
||||
#
|
||||
set -eu -o pipefail
|
||||
|
||||
PROTOBUF_VERSION=3.11.4
|
||||
PROTOBUF_VERSION=3.20.1
|
||||
GOARCH=$(go env GOARCH)
|
||||
GOOS=$(go env GOOS)
|
||||
PROTOBUF_DIR=$(mktemp -d)
|
||||
|
Loading…
Reference in New Issue
Block a user