Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
#
http_archive(
name = "com_google_googleapis",
strip_prefix = "googleapis-b4b8eda2f253cbdab358d2b280468fe5f35a4ed9",
urls = ["https://github.com/googleapis/googleapis/archive/b4b8eda2f253cbdab358d2b280468fe5f35a4ed9.zip"],
sha256 = "7696de036faaccd30c2748e9709c31e6abd6997bcf4648bd43b24d5e5e38ba7a"
strip_prefix = "googleapis-8c42b6d576d865d40398cd67ed37215748721868",
urls = ["https://github.com/googleapis/googleapis/archive/8c42b6d576d865d40398cd67ed37215748721868.zip"],
sha256 = "a17552af336b93a1de63ac67189bd586ad1b8f44abb1dcea9ee5433d8eed5feb"
)
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(name = "com_google_googleapis_imports", grpc = True)
Expand Down
4 changes: 3 additions & 1 deletion client/doc.go

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

8 changes: 6 additions & 2 deletions client/echo_client.go

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

4 changes: 4 additions & 0 deletions cmd/gapic-showcase/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func init() {

EchoCmd.Flags().StringVar(&EchoInputSeverity, "severity", "", "The severity to be echoed by the server.")

EchoCmd.Flags().StringVar(&EchoInput.Header, "header", "", "Optional. This field can be set to test the...")

EchoCmd.Flags().StringVar(&EchoInput.OtherHeader, "other_header", "", "Optional. This field can be set to test the...")

EchoCmd.Flags().StringVar(&EchoInputResponse, "response", "", "Choices: content, error")

EchoCmd.Flags().StringVar(&EchoFromFile, "from_file", "", "Absolute path to JSON file containing request payload")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/googleapis/gapic-showcase
require (
cloud.google.com/go v0.100.2
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.6
github.com/google/go-cmp v0.5.7
github.com/googleapis/gax-go/v2 v2.1.1
github.com/googleapis/grpc-fallback-go v0.1.4
github.com/gorilla/mux v1.8.0
Expand All @@ -14,7 +14,7 @@ require (
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/api v0.65.0
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368
google.golang.org/genproto v0.0.0-20220114231437-d2e6a121cae0
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
)
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -739,8 +740,9 @@ google.golang.org/genproto v0.0.0-20211203200212-54befc351ae9/go.mod h1:5CzLGKJ6
google.golang.org/genproto v0.0.0-20211206160659-862468c7d6e0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211221195035-429b39de9b1c/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 h1:Et6SkiuvnBn+SgrSYXs/BrUpGB4mbdwt4R3vaPIlicA=
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20220114231437-d2e6a121cae0 h1:aCsSLXylHWFno0r4S3joLpiaWayvqd2Mn4iSvx4WZZc=
google.golang.org/genproto v0.0.0-20220114231437-d2e6a121cae0/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
44 changes: 43 additions & 1 deletion schema/google/showcase/v1beta1/echo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ syntax = "proto3";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/routing.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
Expand All @@ -33,7 +34,9 @@ option ruby_package = "Google::Showcase::V1Beta1";
// side streaming, client side streaming, and bidirectional streaming. This
// service also exposes methods that explicitly implement server delay, and
// paginated calls. Set the 'showcase-trailer' metadata key on any method
// to have the values echoed in the response trailers.
// to have the values echoed in the response trailers. Set the
// 'x-goog-request-params' metadata key on any method to have the values
// echoed in the response headers.
service Echo {
// This service is meant to only run locally on the port 7469 (keypad digits
// for "show").
Expand All @@ -45,6 +48,39 @@ service Echo {
post: "/v1beta1/echo:echo"
body: "*"
};
option (google.api.routing) = {
routing_parameters{
field: "header"
}
routing_parameters{
field: "header"
path_template: "{routing_id=**}"
}
routing_parameters{
field: "header"
path_template: "{table_name=regions/*/zones/*/**}"
}
routing_parameters{
field: "header"
path_template: "{super_id=projects/*}/**"
}
routing_parameters{
field: "header"
path_template: "{table_name=projects/*/instances/*/**}"
}
routing_parameters{
field: "header"
path_template: "projects/*/{instance_id=instances/*}/**"
}
routing_parameters{
field: "other_header"
path_template: "{baz=**}"
}
routing_parameters{
field: "other_header"
path_template: "{qux=projects/*}/**"
}
};
}

// This method splits the given content into words and will pass each word back
Expand Down Expand Up @@ -153,6 +189,12 @@ message EchoRequest {

// The severity to be echoed by the server.
Severity severity = 3;

// Optional. This field can be set to test the routing annotation on the Echo method.
string header = 4;

// Optional. This field can be set to test the routing annotation on the Echo method.
string other_header = 5;
}

// The response message for the Echo methods.
Expand Down
36 changes: 36 additions & 0 deletions server/services/echo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (s *echoServerImpl) Echo(ctx context.Context, in *pb.EchoRequest) (*pb.Echo
if err != nil {
return nil, err
}
echoHeaders(ctx)
echoTrailers(ctx)
return &pb.EchoResponse{Content: in.GetContent(), Severity: in.GetSeverity()}, nil
}
Expand All @@ -57,6 +58,7 @@ func (s *echoServerImpl) Expand(in *pb.ExpandRequest, stream pb.Echo_ExpandServe
return err
}
}
echoStreamingHeaders(stream)
if in.GetError() != nil {
return status.ErrorProto(in.GetError())
}
Expand All @@ -70,6 +72,7 @@ func (s *echoServerImpl) Collect(stream pb.Echo_CollectServer) error {
for {
req, err := stream.Recv()
if err == io.EOF {
echoStreamingHeaders(stream)
echoStreamingTrailers(stream)
return stream.SendAndClose(&pb.EchoResponse{Content: strings.Join(resp, " ")})
}
Expand Down Expand Up @@ -101,6 +104,7 @@ func (s *echoServerImpl) Chat(stream pb.Echo_ChatServer) error {
if s != nil {
return s
}
echoStreamingHeaders(stream)
stream.Send(&pb.EchoResponse{Content: req.GetContent()})
}
}
Expand All @@ -127,6 +131,7 @@ func (s *echoServerImpl) PagedExpand(ctx context.Context, in *pb.PagedExpandRequ
responses = append(responses, &pb.EchoResponse{Content: word})
}

echoHeaders(ctx)
echoTrailers(ctx)
return &pb.PagedExpandResponse{
Responses: responses,
Expand Down Expand Up @@ -162,6 +167,7 @@ func (s *echoServerImpl) PagedExpandLegacyMapped(ctx context.Context, in *pb.Pag
}
}

echoHeaders(ctx)
echoTrailers(ctx)
return &pb.PagedExpandLegacyMappedResponse{
Alphabetized: alphabetized,
Expand Down Expand Up @@ -207,6 +213,7 @@ func min(x int32, y int32) int32 {
}

func (s *echoServerImpl) Wait(ctx context.Context, in *pb.WaitRequest) (*lropb.Operation, error) {
echoHeaders(ctx)
echoTrailers(ctx)
return s.waiter.Wait(in), nil
}
Expand All @@ -217,10 +224,39 @@ func (s *echoServerImpl) Block(ctx context.Context, in *pb.BlockRequest) (*pb.Bl
if in.GetError() != nil {
return nil, status.ErrorProto(in.GetError())
}
echoHeaders(ctx)
echoTrailers(ctx)
return in.GetSuccess(), nil
}

//echo any provided headers in the metadata
func echoHeaders(ctx context.Context) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return
}

values := md.Get("x-goog-request-params")
for _, value := range values {
header := metadata.Pairs("x-goog-request-params", value)
grpc.SetHeader(ctx, header)
}
}

func echoStreamingHeaders(stream grpc.ServerStream) {
md, ok := metadata.FromIncomingContext(stream.Context())
if !ok {
return
}
values := md.Get("x-goog-request-params")
for _, value := range values {
header := metadata.Pairs("x-goog-request-params", value)
if stream.SetHeader(header) != nil {
return
}
}
}

// echo any provided trailing metadata
func echoTrailers(ctx context.Context) {
md, ok := metadata.FromIncomingContext(ctx)
Expand Down
Loading