Skip to content

Commit 7f2e950

Browse files
committed
Update ABE example to include a method with no bindings that uses an imported package which is not used by any other method.
1 parent c268540 commit 7f2e950

File tree

6 files changed

+123
-91
lines changed

6 files changed

+123
-91
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package abe
2+
3+
import (
4+
)
5+
6+
type ProtobufDuration struct {
7+
Seconds string `json:"seconds,omitempty"`
8+
Nanos int32 `json:"nanos,omitempty"`
9+
10+
}

examples/examplepb/a_bit_of_everything.pb.go

Lines changed: 92 additions & 89 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: 1 addition & 0 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.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package grpc.gateway.examples.examplepb;
44

55
import "google/api/annotations.proto";
66
import "google/protobuf/empty.proto";
7+
import "google/protobuf/duration.proto";
78
import "examples/sub/message.proto";
89
import "examples/sub2/message.proto";
910
import "google/protobuf/timestamp.proto";
@@ -123,7 +124,7 @@ service ABitOfEverythingService {
123124
body: "*"
124125
};
125126
}
126-
rpc NoBindings(google.protobuf.Empty) returns (google.protobuf.Empty) {}
127+
rpc NoBindings(google.protobuf.Duration) returns (google.protobuf.Empty) {}
127128
rpc Timeout(google.protobuf.Empty) returns (google.protobuf.Empty) {
128129
option (google.api.http) = {
129130
get: "/v2/example/timeout",

examples/examplepb/a_bit_of_everything.swagger.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,22 @@
718718
"default": "ZERO",
719719
"description": "NumericEnum is one or zero.\n\n - ZERO: ZERO means 0\n - ONE: ONE means 1"
720720
},
721+
"protobufDuration": {
722+
"type": "object",
723+
"properties": {
724+
"seconds": {
725+
"type": "string",
726+
"format": "int64",
727+
"description": "Signed seconds of the span of time. Must be from -315,576,000,000\nto +315,576,000,000 inclusive."
728+
},
729+
"nanos": {
730+
"type": "integer",
731+
"format": "int32",
732+
"description": "Signed fractions of a second at nanosecond resolution of the span\nof time. Durations less than one second are represented with a 0\n`seconds` field and a positive or negative `nanos` field. For durations\nof one second or more, a non-zero value for the `nanos` field must be\nof the same sign as the `seconds` field. Must be from -999,999,999\nto +999,999,999 inclusive."
733+
}
734+
},
735+
"description": "A Duration represents a signed, fixed-length span of time represented\nas a count of seconds and fractions of seconds at nanosecond\nresolution. It is independent of any calendar and concepts like \"day\"\nor \"month\". It is related to Timestamp in that the difference between\ntwo Timestamp values is a Duration and it can be added or subtracted\nfrom a Timestamp. Range is approximately +-10,000 years.\n\nExample 1: Compute Duration from two Timestamps in pseudo code.\n\n Timestamp start = ...;\n Timestamp end = ...;\n Duration duration = ...;\n\n duration.seconds = end.seconds - start.seconds;\n duration.nanos = end.nanos - start.nanos;\n\n if (duration.seconds \u003c 0 \u0026\u0026 duration.nanos \u003e 0) {\n duration.seconds += 1;\n duration.nanos -= 1000000000;\n } else if (durations.seconds \u003e 0 \u0026\u0026 duration.nanos \u003c 0) {\n duration.seconds -= 1;\n duration.nanos += 1000000000;\n }\n\nExample 2: Compute Timestamp from Timestamp + Duration in pseudo code.\n\n Timestamp start = ...;\n Duration duration = ...;\n Timestamp end = ...;\n\n end.seconds = start.seconds + duration.seconds;\n end.nanos = start.nanos + duration.nanos;\n\n if (end.nanos \u003c 0) {\n end.seconds -= 1;\n end.nanos += 1000000000;\n } else if (end.nanos \u003e= 1000000000) {\n end.seconds += 1;\n end.nanos -= 1000000000;\n }\n\nExample 3: Compute Duration from datetime.timedelta in Python.\n\n td = datetime.timedelta(days=3, minutes=10)\n duration = Duration()\n duration.FromTimedelta(td)"
736+
},
721737
"protobufEmpty": {
722738
"type": "object",
723739
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",

examples/server/a_bit_of_everything.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77

88
"github.com/golang/glog"
9+
"github.com/golang/protobuf/ptypes/duration"
910
"github.com/golang/protobuf/ptypes/empty"
1011
examples "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb"
1112
sub "github.com/grpc-ecosystem/grpc-gateway/examples/sub"
@@ -234,7 +235,7 @@ func (s *_ABitOfEverythingServer) DeepPathEcho(ctx context.Context, msg *example
234235
return msg, nil
235236
}
236237

237-
func (s *_ABitOfEverythingServer) NoBindings(ctx context.Context, msg *empty.Empty) (*empty.Empty, error) {
238+
func (s *_ABitOfEverythingServer) NoBindings(ctx context.Context, msg *duration.Duration) (*empty.Empty, error) {
238239
return nil, nil
239240
}
240241

0 commit comments

Comments
 (0)