Skip to content

Commit

Permalink
Use google.protobuf.Empty instead of our own
Browse files Browse the repository at this point in the history
  • Loading branch information
yugui committed Jun 13, 2016
1 parent 00ff8da commit 7aec59c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 156 deletions.
190 changes: 91 additions & 99 deletions examples/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion examples/examplepb/a_bit_of_everything.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions examples/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ option go_package = "examplepb";
package gengo.grpc.gateway.examples.examplepb;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "examples/sub/message.proto";
import "examples/sub2/message.proto";

Expand Down Expand Up @@ -45,7 +46,7 @@ message ABitOfEverything {
sint64 sint64_value = 18;
repeated string repeated_string_value = 19;
oneof oneof_value {
EmptyMessage oneof_empty = 20;
google.protobuf.Empty oneof_empty = 20;
string oneof_string = 21;
}

Expand All @@ -56,9 +57,6 @@ message ABitOfEverything {
string nonConventionalNameValue = 26;
}

message EmptyMessage {
}

// NumericEnum is one or zero.
enum NumericEnum {
// ZERO means 0
Expand All @@ -85,13 +83,13 @@ service ABitOfEverythingService {
get: "/v1/example/a_bit_of_everything/{uuid}"
};
}
rpc Update(ABitOfEverything) returns (EmptyMessage) {
rpc Update(ABitOfEverything) returns (google.protobuf.Empty) {
option (google.api.http) = {
put: "/v1/example/a_bit_of_everything/{uuid}"
body: "*"
};
}
rpc Delete(sub2.IdMessage) returns (EmptyMessage) {
rpc Delete(sub2.IdMessage) returns (google.protobuf.Empty) {
option (google.api.http) = {
delete: "/v1/example/a_bit_of_everything/{uuid}"
};
Expand All @@ -114,7 +112,7 @@ service ABitOfEverythingService {
body: "*"
};
}
rpc Timeout(EmptyMessage) returns (EmptyMessage) {
rpc Timeout(google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/v2/example/timeout",
};
Expand Down
16 changes: 9 additions & 7 deletions examples/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"200": {
"description": "Description",
"schema": {
"$ref": "#/definitions/examplepbEmptyMessage"
"$ref": "#/definitions/protobufEmpty"
}
}
},
Expand All @@ -275,7 +275,7 @@
"200": {
"description": "Description",
"schema": {
"$ref": "#/definitions/examplepbEmptyMessage"
"$ref": "#/definitions/protobufEmpty"
}
}
},
Expand Down Expand Up @@ -348,7 +348,7 @@
"200": {
"description": "Description",
"schema": {
"$ref": "#/definitions/examplepbEmptyMessage"
"$ref": "#/definitions/protobufEmpty"
}
}
},
Expand Down Expand Up @@ -450,7 +450,7 @@
"format": "string"
},
"oneof_empty": {
"$ref": "#/definitions/examplepbEmptyMessage"
"$ref": "#/definitions/protobufEmpty"
},
"oneof_string": {
"type": "string",
Expand Down Expand Up @@ -502,9 +502,6 @@
},
"title": "Intentionaly complicated message type to cover much features of Protobuf.\nNEXT ID: 27"
},
"examplepbEmptyMessage": {
"type": "object"
},
"examplepbNumericEnum": {
"type": "string",
"enum": [
Expand All @@ -514,6 +511,11 @@
"default": "ZERO",
"description": "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1"
},
"protobufEmpty": {
"type": "object",
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
"title": "A generic empty message that you can re-use to avoid defining duplicated\nempty messages in your APIs. A typical example is to use it as the request\nor the response type of an API method. For instance:"
},
"sub2IdMessage": {
"type": "object",
"properties": {
Expand Down
1 change: 0 additions & 1 deletion examples/examplepb/echo_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 31 additions & 30 deletions examples/examplepb/stream.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/examplepb/stream.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions examples/examplepb/stream.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ option go_package = "examplepb";
package gengo.grpc.gateway.examples.examplepb;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "examples/examplepb/a_bit_of_everything.proto";
import "examples/sub/message.proto";

// Defines some more operations to be added to ABitOfEverythingService
service StreamService {
rpc BulkCreate(stream ABitOfEverything) returns (EmptyMessage) {
rpc BulkCreate(stream ABitOfEverything) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/v1/example/a_bit_of_everything/bulk"
body: "*"
};
}
rpc List(EmptyMessage) returns (stream ABitOfEverything) {
rpc List(google.protobuf.Empty) returns (stream ABitOfEverything) {
option (google.api.http) = {
get: "/v1/example/a_bit_of_everything"
};
Expand Down
3 changes: 2 additions & 1 deletion examples/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/gengo/grpc-gateway/runtime"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
)
Expand Down Expand Up @@ -363,7 +364,7 @@ func testABEBulkCreate(t *testing.T) {
t.Logf("%s", buf)
}

var msg gw.EmptyMessage
var msg empty.Empty
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
return
Expand Down
15 changes: 8 additions & 7 deletions examples/server/a_bit_of_everything.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sub "github.com/gengo/grpc-gateway/examples/sub"
sub2 "github.com/gengo/grpc-gateway/examples/sub2"
"github.com/golang/glog"
"github.com/golang/protobuf/ptypes/empty"
"github.com/rogpeppe/fastuuid"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (s *_ABitOfEverythingServer) BulkCreate(stream examples.StreamService_BulkC
"foo": "foo2",
"bar": "bar2",
}))
return stream.SendAndClose(new(examples.EmptyMessage))
return stream.SendAndClose(new(empty.Empty))
}

func (s *_ABitOfEverythingServer) Lookup(ctx context.Context, msg *sub2.IdMessage) (*examples.ABitOfEverything, error) {
Expand All @@ -113,7 +114,7 @@ func (s *_ABitOfEverythingServer) Lookup(ctx context.Context, msg *sub2.IdMessag
return nil, grpc.Errorf(codes.NotFound, "not found")
}

func (s *_ABitOfEverythingServer) List(_ *examples.EmptyMessage, stream examples.StreamService_ListServer) error {
func (s *_ABitOfEverythingServer) List(_ *empty.Empty, stream examples.StreamService_ListServer) error {
s.m.Lock()
defer s.m.Unlock()

Expand Down Expand Up @@ -143,7 +144,7 @@ func (s *_ABitOfEverythingServer) List(_ *examples.EmptyMessage, stream examples
return nil
}

func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABitOfEverything) (*examples.EmptyMessage, error) {
func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABitOfEverything) (*empty.Empty, error) {
s.m.Lock()
defer s.m.Unlock()

Expand All @@ -153,10 +154,10 @@ func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABit
} else {
return nil, grpc.Errorf(codes.NotFound, "not found")
}
return new(examples.EmptyMessage), nil
return new(empty.Empty), nil
}

func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessage) (*examples.EmptyMessage, error) {
func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessage) (*empty.Empty, error) {
s.m.Lock()
defer s.m.Unlock()

Expand All @@ -166,7 +167,7 @@ func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessag
} else {
return nil, grpc.Errorf(codes.NotFound, "not found")
}
return new(examples.EmptyMessage), nil
return new(empty.Empty), nil
}

func (s *_ABitOfEverythingServer) Echo(ctx context.Context, msg *sub.StringMessage) (*sub.StringMessage, error) {
Expand Down Expand Up @@ -220,7 +221,7 @@ func (s *_ABitOfEverythingServer) DeepPathEcho(ctx context.Context, msg *example
return msg, nil
}

func (s *_ABitOfEverythingServer) Timeout(ctx context.Context, msg *examples.EmptyMessage) (*examples.EmptyMessage, error) {
func (s *_ABitOfEverythingServer) Timeout(ctx context.Context, msg *empty.Empty) (*empty.Empty, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
Expand Down

2 comments on commit 7aec59c

@tmc
Copy link
Collaborator

@tmc tmc commented on 7aec59c Jun 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing output like

make test
protoc -I /usr/local/bin//../include -I. -Ithird_party/googleapis --plugin=bin/protoc-gen-swagger --swagger_out=logtostderr=true,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/api/annotations.proto=github.com/gengo/grpc-gateway/third_party/googleapis/google/api,Mexamples/sub/message.proto=github.com/gengo/grpc-gateway/examples/sub:. examples/examplepb/echo_service.proto examples/examplepb/a_bit_of_everything.proto
protoc -I /usr/local/bin//../include -I. -Ithird_party/googleapis --plugin=bin/protoc-gen-swagger --swagger_out=logtostderr=true,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/api/annotations.proto=github.com/gengo/grpc-gateway/third_party/googleapis/google/api,Mexamples/sub/message.proto=github.com/gengo/grpc-gateway/examples/sub:. examples/examplepb/echo_service.proto examples/examplepb/a_bit_of_everything.proto
go test -race github.com/gengo/grpc-gateway/...
examples/examplepb/a_bit_of_everything.pb.go:11:8: cannot find package "google/protobuf" in any of:
    /usr/local/Cellar/go/1.6.2/libexec/src/google/protobuf (from $GOROOT)
    /Users/tmc/go/src/google/protobuf (from $GOPATH)

since this commit

@yugui
Copy link
Member Author

@yugui yugui commented on 7aec59c Jun 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmc
Do you have protoc-gen-go newer than golang/protobuf@c75fbf0 and protobuf compiler newer than protocolbuffers/protobuf@3b3c8ab?

Please sign in to comment.