Skip to content

Commit 7aec59c

Browse files
committed
Use google.protobuf.Empty instead of our own
1 parent 00ff8da commit 7aec59c

File tree

10 files changed

+153
-156
lines changed

10 files changed

+153
-156
lines changed

examples/examplepb/a_bit_of_everything.pb.go

Lines changed: 91 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examplepb/a_bit_of_everything.pb.gw.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examplepb/a_bit_of_everything.proto

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ option go_package = "examplepb";
33
package gengo.grpc.gateway.examples.examplepb;
44

55
import "google/api/annotations.proto";
6+
import "google/protobuf/empty.proto";
67
import "examples/sub/message.proto";
78
import "examples/sub2/message.proto";
89

@@ -45,7 +46,7 @@ message ABitOfEverything {
4546
sint64 sint64_value = 18;
4647
repeated string repeated_string_value = 19;
4748
oneof oneof_value {
48-
EmptyMessage oneof_empty = 20;
49+
google.protobuf.Empty oneof_empty = 20;
4950
string oneof_string = 21;
5051
}
5152

@@ -56,9 +57,6 @@ message ABitOfEverything {
5657
string nonConventionalNameValue = 26;
5758
}
5859

59-
message EmptyMessage {
60-
}
61-
6260
// NumericEnum is one or zero.
6361
enum NumericEnum {
6462
// ZERO means 0
@@ -85,13 +83,13 @@ service ABitOfEverythingService {
8583
get: "/v1/example/a_bit_of_everything/{uuid}"
8684
};
8785
}
88-
rpc Update(ABitOfEverything) returns (EmptyMessage) {
86+
rpc Update(ABitOfEverything) returns (google.protobuf.Empty) {
8987
option (google.api.http) = {
9088
put: "/v1/example/a_bit_of_everything/{uuid}"
9189
body: "*"
9290
};
9391
}
94-
rpc Delete(sub2.IdMessage) returns (EmptyMessage) {
92+
rpc Delete(sub2.IdMessage) returns (google.protobuf.Empty) {
9593
option (google.api.http) = {
9694
delete: "/v1/example/a_bit_of_everything/{uuid}"
9795
};
@@ -114,7 +112,7 @@ service ABitOfEverythingService {
114112
body: "*"
115113
};
116114
}
117-
rpc Timeout(EmptyMessage) returns (EmptyMessage) {
115+
rpc Timeout(google.protobuf.Empty) returns (google.protobuf.Empty) {
118116
option (google.api.http) = {
119117
get: "/v2/example/timeout",
120118
};

examples/examplepb/a_bit_of_everything.swagger.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
"200": {
253253
"description": "Description",
254254
"schema": {
255-
"$ref": "#/definitions/examplepbEmptyMessage"
255+
"$ref": "#/definitions/protobufEmpty"
256256
}
257257
}
258258
},
@@ -275,7 +275,7 @@
275275
"200": {
276276
"description": "Description",
277277
"schema": {
278-
"$ref": "#/definitions/examplepbEmptyMessage"
278+
"$ref": "#/definitions/protobufEmpty"
279279
}
280280
}
281281
},
@@ -348,7 +348,7 @@
348348
"200": {
349349
"description": "Description",
350350
"schema": {
351-
"$ref": "#/definitions/examplepbEmptyMessage"
351+
"$ref": "#/definitions/protobufEmpty"
352352
}
353353
}
354354
},
@@ -450,7 +450,7 @@
450450
"format": "string"
451451
},
452452
"oneof_empty": {
453-
"$ref": "#/definitions/examplepbEmptyMessage"
453+
"$ref": "#/definitions/protobufEmpty"
454454
},
455455
"oneof_string": {
456456
"type": "string",
@@ -502,9 +502,6 @@
502502
},
503503
"title": "Intentionaly complicated message type to cover much features of Protobuf.\nNEXT ID: 27"
504504
},
505-
"examplepbEmptyMessage": {
506-
"type": "object"
507-
},
508505
"examplepbNumericEnum": {
509506
"type": "string",
510507
"enum": [
@@ -514,6 +511,11 @@
514511
"default": "ZERO",
515512
"description": "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1"
516513
},
514+
"protobufEmpty": {
515+
"type": "object",
516+
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
517+
"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:"
518+
},
517519
"sub2IdMessage": {
518520
"type": "object",
519521
"properties": {

examples/examplepb/echo_service.pb.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examplepb/stream.pb.go

Lines changed: 31 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examplepb/stream.pb.gw.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/examplepb/stream.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ option go_package = "examplepb";
33
package gengo.grpc.gateway.examples.examplepb;
44

55
import "google/api/annotations.proto";
6+
import "google/protobuf/empty.proto";
67
import "examples/examplepb/a_bit_of_everything.proto";
78
import "examples/sub/message.proto";
89

910
// Defines some more operations to be added to ABitOfEverythingService
1011
service StreamService {
11-
rpc BulkCreate(stream ABitOfEverything) returns (EmptyMessage) {
12+
rpc BulkCreate(stream ABitOfEverything) returns (google.protobuf.Empty) {
1213
option (google.api.http) = {
1314
post: "/v1/example/a_bit_of_everything/bulk"
1415
body: "*"
1516
};
1617
}
17-
rpc List(EmptyMessage) returns (stream ABitOfEverything) {
18+
rpc List(google.protobuf.Empty) returns (stream ABitOfEverything) {
1819
option (google.api.http) = {
1920
get: "/v1/example/a_bit_of_everything"
2021
};

examples/integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/gengo/grpc-gateway/runtime"
1919
"github.com/golang/protobuf/jsonpb"
2020
"github.com/golang/protobuf/proto"
21+
"github.com/golang/protobuf/ptypes/empty"
2122
"golang.org/x/net/context"
2223
"google.golang.org/grpc/codes"
2324
)
@@ -363,7 +364,7 @@ func testABEBulkCreate(t *testing.T) {
363364
t.Logf("%s", buf)
364365
}
365366

366-
var msg gw.EmptyMessage
367+
var msg empty.Empty
367368
if err := jsonpb.UnmarshalString(string(buf), &msg); err != nil {
368369
t.Errorf("jsonpb.UnmarshalString(%s, &msg) failed with %v; want success", buf, err)
369370
return

examples/server/a_bit_of_everything.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
sub "github.com/gengo/grpc-gateway/examples/sub"
1010
sub2 "github.com/gengo/grpc-gateway/examples/sub2"
1111
"github.com/golang/glog"
12+
"github.com/golang/protobuf/ptypes/empty"
1213
"github.com/rogpeppe/fastuuid"
1314
"golang.org/x/net/context"
1415
"google.golang.org/grpc"
@@ -87,7 +88,7 @@ func (s *_ABitOfEverythingServer) BulkCreate(stream examples.StreamService_BulkC
8788
"foo": "foo2",
8889
"bar": "bar2",
8990
}))
90-
return stream.SendAndClose(new(examples.EmptyMessage))
91+
return stream.SendAndClose(new(empty.Empty))
9192
}
9293

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

116-
func (s *_ABitOfEverythingServer) List(_ *examples.EmptyMessage, stream examples.StreamService_ListServer) error {
117+
func (s *_ABitOfEverythingServer) List(_ *empty.Empty, stream examples.StreamService_ListServer) error {
117118
s.m.Lock()
118119
defer s.m.Unlock()
119120

@@ -143,7 +144,7 @@ func (s *_ABitOfEverythingServer) List(_ *examples.EmptyMessage, stream examples
143144
return nil
144145
}
145146

146-
func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABitOfEverything) (*examples.EmptyMessage, error) {
147+
func (s *_ABitOfEverythingServer) Update(ctx context.Context, msg *examples.ABitOfEverything) (*empty.Empty, error) {
147148
s.m.Lock()
148149
defer s.m.Unlock()
149150

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

159-
func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessage) (*examples.EmptyMessage, error) {
160+
func (s *_ABitOfEverythingServer) Delete(ctx context.Context, msg *sub2.IdMessage) (*empty.Empty, error) {
160161
s.m.Lock()
161162
defer s.m.Unlock()
162163

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

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

223-
func (s *_ABitOfEverythingServer) Timeout(ctx context.Context, msg *examples.EmptyMessage) (*examples.EmptyMessage, error) {
224+
func (s *_ABitOfEverythingServer) Timeout(ctx context.Context, msg *empty.Empty) (*empty.Empty, error) {
224225
select {
225226
case <-ctx.Done():
226227
return nil, ctx.Err()

0 commit comments

Comments
 (0)