Use google.golang.org/protobuf instead of github.com/gogo/protobuf

This change replaces github.com/gogo/protobuf with
google.golang.org/protobuf, except for the code generators.

All proto-encoded structs are now generated from .proto files,
which include ttrpc.Request and ttrpc.Response.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
Kazuyoshi Kato
2022-02-16 22:32:47 +00:00
parent 332f4c9a9b
commit d240c5005f
20 changed files with 1011 additions and 955 deletions

View File

@@ -1,6 +1,5 @@
version = "unstable"
generator = "gogottrpc"
plugins = ["ttrpc"]
version = "2"
generators = ["go", "go-ttrpc"]
# Control protoc include paths. Below are usually some good defaults, but feel
# free to try it without them if it works for your project.
@@ -9,11 +8,6 @@ plugins = ["ttrpc"]
# treat the root of the project as an include, but this may not be necessary.
# before = ["./protobuf"]
# Paths that should be treated as include roots in relation to the vendor
# directory. These will be calculated with the vendor directory nearest the
# target package.
packages = ["github.com/gogo/protobuf"]
# Paths that will be added untouched to the end of the includes. We use
# `/usr/local/include` to pickup the common install location of protobuf.
# This is the default.
@@ -22,11 +16,4 @@ plugins = ["ttrpc"]
# This section maps protobuf imports to Go packages. These will become
# `-M` directives in the call to the go protobuf generator.
[packages]
"gogoproto/gogo.proto" = "github.com/gogo/protobuf/gogoproto"
"google/protobuf/any.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/empty.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/descriptor.proto" = "github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"google/protobuf/field_mask.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/timestamp.proto" = "github.com/gogo/protobuf/types"
"google/protobuf/duration.proto" = "github.com/gogo/protobuf/types"
"google/rpc/status.proto" = "github.com/containerd/containerd/protobuf/google/rpc"

View File

@@ -26,7 +26,7 @@ import (
ttrpc "github.com/containerd/ttrpc"
"github.com/containerd/ttrpc/example"
"github.com/gogo/protobuf/types"
"google.golang.org/protobuf/types/known/emptypb"
)
const socket = "example-ttrpc-server"
@@ -130,6 +130,6 @@ func (s *exampleServer) Method1(ctx context.Context, r *example.Method1Request)
}, nil
}
func (s *exampleServer) Method2(ctx context.Context, r *example.Method1Request) (*types.Empty, error) {
return &types.Empty{}, nil
func (s *exampleServer) Method2(ctx context.Context, r *example.Method1Request) (*emptypb.Empty, error) {
return &emptypb.Empty{}, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,6 @@ syntax = "proto3";
package ttrpc.example.v1;
import "google/protobuf/empty.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/containerd/ttrpc/example;example";

View File

@@ -0,0 +1,57 @@
// Code generated by protoc-gen-go-ttrpc. DO NOT EDIT.
// source: github.com/containerd/ttrpc/example/example.proto
package example
import (
context "context"
ttrpc "github.com/containerd/ttrpc"
empty "github.com/golang/protobuf/ptypes/empty"
)
type ExampleService interface {
Method1(ctx context.Context, req *Method1Request) (*Method1Response, error)
Method2(ctx context.Context, req *Method1Request) (*empty.Empty, error)
}
func RegisterExampleService(srv *ttrpc.Server, svc ExampleService) {
srv.Register("ttrpc.example.v1.Example", map[string]ttrpc.Method{
"Method1": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
var req Method1Request
if err := unmarshal(&req); err != nil {
return nil, err
}
return svc.Method1(ctx, &req)
},
"Method2": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
var req Method1Request
if err := unmarshal(&req); err != nil {
return nil, err
}
return svc.Method2(ctx, &req)
},
})
}
type exampleClient struct {
client *ttrpc.Client
}
func NewExampleClient(client *ttrpc.Client) ExampleService {
return &exampleClient{
client: client,
}
}
func (c *exampleClient) Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) {
var resp Method1Response
if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method1", req, &resp); err != nil {
return nil, err
}
return &resp, nil
}
func (c *exampleClient) Method2(ctx context.Context, req *Method1Request) (*empty.Empty, error) {
var resp empty.Empty
if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method2", req, &resp); err != nil {
return nil, err
}
return &resp, nil
}