diff --git a/.circleci/config.yml b/.circleci/config.yml index 531fa78..69fa76a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,9 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/golang:1.11.6-stretch - working_directory: /go/src/github.com/buoyantio/bb + - image: cimg/go:1.22.3 steps: - checkout - - run: bin/dep ensure -vendor-only - run: bin/precheck.sh diff --git a/.dockerignore b/.dockerignore index c2e3388..973bca2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ -.dep -vendor \ No newline at end of file +vendor +target diff --git a/.gitignore b/.gitignore index feabeed..973bca2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ vendor target -.idea -.protoc -.dep* diff --git a/Dockerfile b/Dockerfile index 3741edc..63a2e34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,22 @@ -FROM golang:1.11.6-stretch as golang -WORKDIR /go/src/github.com/buoyantio/bb -ADD . /go/src/github.com/buoyantio/bb +# cache go modules in a separate image +FROM --platform=$BUILDPLATFORM golang:1.22.3-alpine as go-deps +WORKDIR /bb-build +COPY go.mod go.sum main.go ./ +COPY cmd cmd +COPY gen gen +COPY protocols protocols +COPY service service +COPY strategies strategies +RUN go mod vendor -RUN mkdir -p /out -RUN ./bin/dep ensure -RUN go build -o /out/bb . +# build the bb binary +FROM --platform=$BUILDPLATFORM go-deps as golang +WORKDIR /bb-build +RUN CGO_ENABLED=0 go build -o /out/bb -mod=vendor . -FROM gcr.io/linkerd-io/base:2019-02-19.01 -RUN apt-get update -RUN apt-get install -y ca-certificates -COPY --from=golang /out /out +# package a runtime image +FROM scratch +LABEL org.opencontainers.image.source=https://github.com/buoyantio/bb +COPY --from=golang /out/bb /out/bb +COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ ENTRYPOINT ["/out/bb"] diff --git a/README.md b/README.md index fc0e709..da4d8bf 100644 --- a/README.md +++ b/README.md @@ -3,32 +3,32 @@ # bb -Building Blocks or `bb` is a tool that can simulate many of the typical scenarios -of a cloud-native Service-Oriented Architecture based on microservices. +Building Blocks or `bb` is a tool that can simulate many of the typical +scenarios of a cloud-native Service-Oriented Architecture based on +microservices. ## Using `bb` -`bb` publishes a single container, `buoyantio/bb:v0.0.5`. Instances of this -container receive and return a simple message, described by the protobuf schema -[in this repository](api.proto). This known interface allows for `bb` -containers to be arranged in many different ways, just like building a structure -using LEGO blocks. +`bb` publishes a single container, `buoyantio/bb`. Instances of this container +receive and return a simple message, described by the protobuf schema [in this +repository](api.proto). This known interface allows for `bb` containers to be +arranged in many different ways, like building a structure using LEGO blocks. -The best way to find out about `bb` features is by using the `--help` command and -checking out the self-contained documentation. +The best way to find out about `bb` features is by using the `--help` command +and checking out the self-contained documentation. ### Running locally -If you want to run `bb` locally, outside a Kubernetes cluster or Docker, you need -to build a binary for your environment. The usual way to go about this is using Go's -standard build tools. From this repository's root, run: +If you want to run `bb` locally, outside a Kubernetes cluster or Docker, you +need to build a binary for your environment. The usual way to go about this is +using Go's standard build tools. From this repository's root, run: $ mkdir -p target && go build -o target/bb . -This will create a `bb` binary in the `target` directory. You can run this on your -computer but, unless you use Linux, you won't be able to use this same binary on -Docker or Kubernetes. +This will create a `bb` binary in the `target` directory. You can run this on +your computer but, unless you use Linux, you won't be able to use this same +binary on Docker or Kubernetes. -As an example of how to use `bb` on your computer, let's create a simple two-service -setup. Open a terminal and type in the following: +As an example of how to use `bb` on your computer, let's create a simple +two-service setup. Open a terminal and type in the following: $ target/bb terminus --grpc-server-port 9090 --response-text BANANA @@ -41,50 +41,37 @@ Now, on a third terminal, type this and you should see a similar response: $ curl localhost:8080 {"requestUid":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-387107000","payload":"BANANA"} -The first command you typed created a gRPC server on port 9090 following the [terminus strategy](strategies/terminus.go), -which will return the payload defined as the `--response-text` argument for any valid request. +The first command you typed created a gRPC server on port 9090 following the +[terminus strategy](strategies/terminus.go), which will return the payload +defined as the `--response-text` argument for any valid request. The second command creates an HTTP 1.1 server on port 8080 following the -[point-to-point channel strategy](strategies/point_to_point_channel.go), and has the gRPC server -previously defined as its downstream. It will receive any HTTP 1.1 request, convert it to gRPC, -and forward it to the downstream server. It will also get the gRPC response from the server, convert -it to JSON-over-HTTP, and return to its client. +[point-to-point channel strategy](strategies/point_to_point_channel.go), and has +the gRPC server previously defined as its downstream. It will receive any HTTP +1.1 request, convert it to gRPC, and forward it to the downstream server. It +will also get the gRPC response from the server, convert it to JSON-over-HTTP, +and return to its client. ## Running on Kubernetes -Although `bb` can be useful to test things locally as described above, its main use case is to create -complicated environments inside Kubernetes clusters. +Although `bb` can be useful to test things locally as described above, its main +use case is to create complicated environments inside Kubernetes clusters. -To use `bb` with Kubernetes, the first step you need to take is to publish its Docker image to your -Kubernetes cluster. Here we will be using a local Minikube installation to demonstrate its use. +To use `bb` with Kubernetes, the first step you need to take is to publish its +Docker image to your Kubernetes cluster. Here we will be using a local [kind +cluster](https://kind.sigs.k8s.io/) to demonstrate its use. -First, make sure that Minikube is running: +First, start your cluster: - $ minikube status - minikube: Running - cluster: Running - kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100 - -Now, make sure that your Docker environment variables are set to use Minikube as the Docker repository -for images: - - $ eval "$(minikube docker-env)" + $ kind create cluster You should then build a Docker image for `bb`: - $ bin/docker-build-bb.sh - Sending build context to Docker daemon 136.7MB - Step 1/6 : FROM buoyantio/base:2017-10-30.01 - ---> 14aa74f25501 - Step 2/6 : RUN apt-get update - [...] - Removing intermediate container f4f571b01dd8 - Successfully built e6d76c5df612 - Successfully tagged buoyantio/bb:v0.0.5 - -A test run using the Docker CLI should return usage information and confirm that everything is ok: + $ docker build -t buoyantio/bb:latest . - $ docker run buoyantio/bb:v0.0.5 +A test run using the Docker CLI should return usage information and confirm that +everything is ok: + $ docker run buoyantio/bb:latest Building Blocks or `bb` is a tool that can simulate many of the typical scenarios of a cloud-native Service-Oriented Architecture based on microservices. Usage: @@ -92,6 +79,7 @@ A test run using the Docker CLI should return usage information and confirm that Available Commands: broadcast-channel Forwards the request to all downstream services. + completion Generate the autocompletion script for the specified shell help Help about any command http-egress Receives a request, makes a HTTP(S) call to a specified URL and return the body of the response point-to-point-channel Forwards the request to one and only one downstream service. @@ -114,13 +102,21 @@ A test run using the Docker CLI should return usage information and confirm that Use "bb [command] --help" for more information about a command. -To build the exact same scenario we had above, but for Kubernetes, you can deploy the should have -a YAML configuration like the one in our [examples directory](examples). You can deploy it to your Kubernetes -cluster by running: +Next load the image into your kind cluster, with: + + $ kind load docker-image buoyantio/bb:latest + +To build the exact same scenario we had above, but for Kubernetes, you can +deploy a YAML configuration like the one in our [examples directory](examples). +You can deploy it to your Kubernetes cluster by running: $ kubectl apply -f examples/bb-readme/application.yaml -You can then use `curl`to query the service: +You can then port-forward and use `curl` to query the service: + + $ kubectl -n bb-readme port-forward svc/bb-readme-gateway-svc 8080 & + Forwarding from [::1]:8080 -> 8080 - $ curl `minikube -n bb-readme service bb-readme-gateway-svc --url` - {"requestUid":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-66349706","payload":"BANANA"} + $ curl http://localhost:8080 + Handling connection for 8080 + {"requestUID":"in:http-sid:point-to-point-channel-grpc:-1-h1:8080-395520418","payload":"BANANA"} diff --git a/api.proto b/api.proto index 4dd5c82..dafd86c 100644 --- a/api.proto +++ b/api.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package buoyantio.bb; +option go_package = "github.com/buoyantio/bb/gen"; + message TheRequest { string requestUID = 1; } @@ -14,4 +16,4 @@ message TheResponse { service TheService { rpc theFunction (TheRequest) returns (TheResponse) { } -} \ No newline at end of file +} diff --git a/bin/dep b/bin/dep deleted file mode 100755 index baedda4..0000000 --- a/bin/dep +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -# bash is required since indirect variable substitution is used. - -set -eu - -# Keep this in sync with Dockerfile-go-deps. The digests will be different for each -# version and each platform; they can be found in the *.sha256 files alongside the -# executables at ${dep_base_url}. -depversion=0.5.0 -dep_base_url="https://github.com/golang/dep/releases/download/v${depversion}/" - -cd "$(pwd -P)" - -bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -rootdir="$( cd $bindir/.. && pwd )" - -os=linux -exe= -if [ "$(uname -s)" = "Darwin" ]; then - os=darwin -elif [ "$(uname -o)" = "Msys" ]; then - os=windows - exe=.exe -fi - -depbin="${rootdir}/.dep-${depversion}${exe}" -depurl="${dep_base_url}dep-${os}-amd64${exe}" - -if [ ! -f "$depbin" ]; then - tmp=$(mktemp -d -t dep.XXX) - ( - cd "$tmp" - curl -L --silent --fail -o depbin "$depurl" - sha=$(curl -L --silent --fail "${depurl}.sha256" | awk '{ print $1 }') - (echo "$sha *depbin" | shasum -c -a 256 -p -s -) || { - echo "Actual digest of $(pwd)/depbin does not match expected digest." - exit 1 - } - chmod +x depbin - ) - mv "$tmp/depbin" "$depbin" - rm -rf "$tmp" -fi - -$depbin "$@" diff --git a/bin/docker-build-bb.sh b/bin/docker-build-bb.sh deleted file mode 100755 index 5070822..0000000 --- a/bin/docker-build-bb.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -docker build -f ./Dockerfile . -t buoyantio/bb:latest diff --git a/bin/protoc b/bin/protoc index 8a1f728..d9569dd 100755 --- a/bin/protoc +++ b/bin/protoc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash set -eu @@ -9,16 +9,19 @@ else fi arch=$(uname -m) -protocbin=.protoc -protocversion=3.4.0 -protocurl="https://github.com/google/protobuf/releases/download/v${protocversion}/protoc-${protocversion}-${os}-${arch}.zip" +protocversion=3.20.1 + +targetbin=target/bin +protocbin=$targetbin/protoc-${protocversion} +protocurl="https://github.com/protocolbuffers/protobuf/releases/download/v${protocversion}/protoc-${protocversion}-${os}-${arch}.zip" if [ ! -f "$protocbin" ]; then tmp=$(mktemp -d -t protoc.XXX) + mkdir -p $targetbin ( - cd $tmp - curl -L --silent --fail -o "$protocbin.zip" "$protocurl" - jar xf "$protocbin.zip" + cd "$tmp" + curl -L --silent --fail -o "./protoc.zip" "$protocurl" + unzip -q "./protoc.zip" bin/protoc chmod +x bin/protoc ) mv "$tmp/bin/protoc" "$protocbin" diff --git a/bin/protoc-go.sh b/bin/protoc-go.sh index 174e759..5fe634c 100755 --- a/bin/protoc-go.sh +++ b/bin/protoc-go.sh @@ -1,12 +1,25 @@ -#!/bin/sh +#!/usr/bin/env bash set -eu -generated_src_dir=./gen +# keep in sync with google.golang.org/protobuf in go.mod +protoc_gen_go_version=v1.33.0 +# keep in sync with google.golang.org/grpc/cmd/protoc-gen-go-grpc in go.mod +protoc_gen_go_grpc_version=v1.3.0 -go install ./vendor/github.com/golang/protobuf/protoc-gen-go +# fetch tools and dependencies +go install google.golang.org/protobuf/cmd/protoc-gen-go@$protoc_gen_go_version +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$protoc_gen_go_grpc_version -rm -rf $generated_src_dir -mkdir $generated_src_dir -bin/protoc -I . --go_out=plugins=grpc:$generated_src_dir ./api.proto +basedir=$(cd "$(dirname "$0")"/..; pwd) +outdir="$basedir"/gen +rm -rf "$outdir" +mkdir "$outdir" +"$basedir"/bin/protoc \ + --proto_path="$basedir" \ + --go_out="$outdir" \ + --go_opt=paths=source_relative \ + --go-grpc_out="$outdir" \ + --go-grpc_opt=paths=source_relative \ + "$basedir"/api.proto diff --git a/examples/bb-readme/application.yaml b/examples/bb-readme/application.yaml index ea96b95..a2ccccb 100644 --- a/examples/bb-readme/application.yaml +++ b/examples/bb-readme/application.yaml @@ -4,7 +4,7 @@ kind: Namespace metadata: name: bb-readme --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: bb-readme-terminus @@ -21,7 +21,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "9090", "--response-text", "BANANA"] ports: - containerPort: 9090 @@ -39,7 +39,7 @@ spec: port: 9090 targetPort: 9090 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: bb-readme-gateway @@ -56,7 +56,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["point-to-point-channel", "--grpc-downstream-server", "bb-readme-terminus-svc:9090", "--h1-server-port", "8080"] ports: - containerPort: 8080 @@ -69,7 +69,6 @@ metadata: spec: selector: app: bb-readme-gateway - type: LoadBalancer ports: - name: http port: 8080 diff --git a/examples/heavy-east-west/application.yaml b/examples/heavy-east-west/application.yaml index 0ced3b7..628e3c2 100644 --- a/examples/heavy-east-west/application.yaml +++ b/examples/heavy-east-west/application.yaml @@ -6,7 +6,7 @@ metadata: ## Layer: Api Gateway --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: api-gateway @@ -23,7 +23,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--h1-downstream-server", "http://heavy-east-west-lab-t1-n1-svc:80", "--h1-downstream-server", "http://heavy-east-west-lab-t1-n2-svc:80", @@ -51,7 +51,7 @@ spec: ## Layer: First row of broadcasters ### t1-n1 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t1-n1 @@ -68,7 +68,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n1-svc:80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n2-svc:80", @@ -93,7 +93,7 @@ spec: targetPort: 80 ### t1-n2 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t1-n2 @@ -110,7 +110,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n1-svc:80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n2-svc:80", @@ -135,7 +135,7 @@ spec: targetPort: 80 ### t1-n3 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t1-n3 @@ -152,7 +152,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n1-svc:80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n2-svc:80", @@ -177,7 +177,7 @@ spec: targetPort: 80 ### t1-n4 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t1-n4 @@ -194,7 +194,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n1-svc:80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n2-svc:80", @@ -219,7 +219,7 @@ spec: targetPort: 80 ### t1-n5 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t1-n5 @@ -236,7 +236,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["broadcast-channel", "--h1-server-port", "80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n1-svc:80", "--grpc-downstream-server", "heavy-east-west-lab-t2-n2-svc:80", @@ -263,7 +263,7 @@ spec: ## Layer: End layer of termini ### t2-n1 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t2-n1 @@ -280,7 +280,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "80", "--response-text", "t2-n1", "--fire-and-forget"] ports: @@ -300,7 +300,7 @@ spec: targetPort: 80 ### t2-n2 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t2-n2 @@ -317,7 +317,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "80", "--response-text", "t2-n2", "--fire-and-forget"] ports: @@ -337,7 +337,7 @@ spec: targetPort: 80 ### t2-n3 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t2-n3 @@ -354,7 +354,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "80", "--response-text", "t2-n3", "--fire-and-forget"] ports: @@ -374,7 +374,7 @@ spec: targetPort: 80 ### t2-n4 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t2-n4 @@ -391,7 +391,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "80", "--response-text", "t2-n4", "--fire-and-forget"] ports: @@ -411,7 +411,7 @@ spec: targetPort: 80 ### t2-n5 --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: heavy-east-west-lab-t2-n5 @@ -428,7 +428,7 @@ spec: spec: containers: - name: http-to-grpc - image: buoyantio/bb:v0.0.5 + image: buoyantio/bb:latest args: ["terminus", "--grpc-server-port", "80", "--response-text", "t2-n5", "--fire-and-forget"] ports: diff --git a/examples/http-egress/application.yaml b/examples/http-egress/application.yaml new file mode 100644 index 0000000..4dc294a --- /dev/null +++ b/examples/http-egress/application.yaml @@ -0,0 +1,75 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: http-egress +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: http-egress + namespace: http-egress +spec: + replicas: 1 + selector: + matchLabels: + app: http-egress + template: + metadata: + labels: + app: http-egress + spec: + containers: + - name: http-egress + image: buoyantio/bb:latest + args: ["http-egress", "--h1-server-port", "8081", "--url", "https://versioncheck.linkerd.io/version.json"] + ports: + - containerPort: 8081 +--- +apiVersion: v1 +kind: Service +metadata: + name: http-egress-svc + namespace: http-egress +spec: + selector: + app: http-egress + ports: + - name: http + port: 8081 + targetPort: 8081 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: http-egress-gateway + namespace: http-egress +spec: + replicas: 1 + selector: + matchLabels: + app: http-egress-gateway + template: + metadata: + labels: + app: http-egress-gateway + spec: + containers: + - name: http-to-http-egress + image: buoyantio/bb:latest + args: ["point-to-point-channel", "--h1-server-port", "8080", "--h1-downstream-server", "http://http-egress-svc:8081"] + ports: + - containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: http-egress-gateway-svc + namespace: http-egress +spec: + selector: + app: http-egress-gateway + ports: + - name: http + port: 8080 + targetPort: 8080 diff --git a/gen/api.pb.go b/gen/api.pb.go index 38c2bbe..fb6feb0 100644 --- a/gen/api.pb.go +++ b/gen/api.pb.go @@ -1,202 +1,223 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.33.0 +// protoc v3.20.1 // source: api.proto -package buoyantio_bb - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +package gen import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type TheRequest struct { - RequestUID string `protobuf:"bytes,1,opt,name=requestUID,proto3" json:"requestUID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *TheRequest) Reset() { *m = TheRequest{} } -func (m *TheRequest) String() string { return proto.CompactTextString(m) } -func (*TheRequest) ProtoMessage() {} -func (*TheRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_api_a4df1ba5ef4ed377, []int{0} + RequestUID string `protobuf:"bytes,1,opt,name=requestUID,proto3" json:"requestUID,omitempty"` } -func (m *TheRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TheRequest.Unmarshal(m, b) -} -func (m *TheRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TheRequest.Marshal(b, m, deterministic) -} -func (dst *TheRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_TheRequest.Merge(dst, src) -} -func (m *TheRequest) XXX_Size() int { - return xxx_messageInfo_TheRequest.Size(m) + +func (x *TheRequest) Reset() { + *x = TheRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *TheRequest) XXX_DiscardUnknown() { - xxx_messageInfo_TheRequest.DiscardUnknown(m) + +func (x *TheRequest) String() string { + return protoimpl.X.MessageStringOf(x) } -var xxx_messageInfo_TheRequest proto.InternalMessageInfo +func (*TheRequest) ProtoMessage() {} -func (m *TheRequest) GetRequestUID() string { - if m != nil { - return m.RequestUID +func (x *TheRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - return "" + return mi.MessageOf(x) } -type TheResponse struct { - RequestUID string `protobuf:"bytes,1,opt,name=requestUID,proto3" json:"requestUID,omitempty"` - Payload string `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` +// Deprecated: Use TheRequest.ProtoReflect.Descriptor instead. +func (*TheRequest) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{0} } -func (m *TheResponse) Reset() { *m = TheResponse{} } -func (m *TheResponse) String() string { return proto.CompactTextString(m) } -func (*TheResponse) ProtoMessage() {} -func (*TheResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_api_a4df1ba5ef4ed377, []int{1} -} -func (m *TheResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_TheResponse.Unmarshal(m, b) -} -func (m *TheResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_TheResponse.Marshal(b, m, deterministic) -} -func (dst *TheResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_TheResponse.Merge(dst, src) -} -func (m *TheResponse) XXX_Size() int { - return xxx_messageInfo_TheResponse.Size(m) -} -func (m *TheResponse) XXX_DiscardUnknown() { - xxx_messageInfo_TheResponse.DiscardUnknown(m) +func (x *TheRequest) GetRequestUID() string { + if x != nil { + return x.RequestUID + } + return "" } -var xxx_messageInfo_TheResponse proto.InternalMessageInfo +type TheResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *TheResponse) GetRequestUID() string { - if m != nil { - return m.RequestUID - } - return "" + RequestUID string `protobuf:"bytes,1,opt,name=requestUID,proto3" json:"requestUID,omitempty"` + Payload string `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` } -func (m *TheResponse) GetPayload() string { - if m != nil { - return m.Payload +func (x *TheResponse) Reset() { + *x = TheResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } - return "" } -func init() { - proto.RegisterType((*TheRequest)(nil), "buoyantio.bb.TheRequest") - proto.RegisterType((*TheResponse)(nil), "buoyantio.bb.TheResponse") +func (x *TheResponse) String() string { + return protoimpl.X.MessageStringOf(x) } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +func (*TheResponse) ProtoMessage() {} -// TheServiceClient is the client API for TheService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type TheServiceClient interface { - TheFunction(ctx context.Context, in *TheRequest, opts ...grpc.CallOption) (*TheResponse, error) +func (x *TheResponse) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -type theServiceClient struct { - cc *grpc.ClientConn +// Deprecated: Use TheResponse.ProtoReflect.Descriptor instead. +func (*TheResponse) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{1} } -func NewTheServiceClient(cc *grpc.ClientConn) TheServiceClient { - return &theServiceClient{cc} +func (x *TheResponse) GetRequestUID() string { + if x != nil { + return x.RequestUID + } + return "" } -func (c *theServiceClient) TheFunction(ctx context.Context, in *TheRequest, opts ...grpc.CallOption) (*TheResponse, error) { - out := new(TheResponse) - err := c.cc.Invoke(ctx, "/buoyantio.bb.TheService/theFunction", in, out, opts...) - if err != nil { - return nil, err +func (x *TheResponse) GetPayload() string { + if x != nil { + return x.Payload } - return out, nil + return "" } -// TheServiceServer is the server API for TheService service. -type TheServiceServer interface { - TheFunction(context.Context, *TheRequest) (*TheResponse, error) +var File_api_proto protoreflect.FileDescriptor + +var file_api_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0c, 0x62, 0x75, 0x6f, + 0x79, 0x61, 0x6e, 0x74, 0x69, 0x6f, 0x2e, 0x62, 0x62, 0x22, 0x2c, 0x0a, 0x0a, 0x54, 0x68, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x55, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x55, 0x49, 0x44, 0x22, 0x47, 0x0a, 0x0b, 0x54, 0x68, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x55, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x55, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x32, 0x52, 0x0a, 0x0a, 0x54, 0x68, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x44, + 0x0a, 0x0b, 0x74, 0x68, 0x65, 0x46, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x2e, + 0x62, 0x75, 0x6f, 0x79, 0x61, 0x6e, 0x74, 0x69, 0x6f, 0x2e, 0x62, 0x62, 0x2e, 0x54, 0x68, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x62, 0x75, 0x6f, 0x79, 0x61, 0x6e, + 0x74, 0x69, 0x6f, 0x2e, 0x62, 0x62, 0x2e, 0x54, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x1d, 0x5a, 0x1b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x6f, 0x79, 0x61, 0x6e, 0x74, 0x69, 0x6f, 0x2f, 0x62, 0x62, 0x2f, + 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_api_proto_rawDescOnce sync.Once + file_api_proto_rawDescData = file_api_proto_rawDesc +) + +func file_api_proto_rawDescGZIP() []byte { + file_api_proto_rawDescOnce.Do(func() { + file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData) + }) + return file_api_proto_rawDescData } -func RegisterTheServiceServer(s *grpc.Server, srv TheServiceServer) { - s.RegisterService(&_TheService_serviceDesc, srv) +var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_api_proto_goTypes = []interface{}{ + (*TheRequest)(nil), // 0: buoyantio.bb.TheRequest + (*TheResponse)(nil), // 1: buoyantio.bb.TheResponse +} +var file_api_proto_depIdxs = []int32{ + 0, // 0: buoyantio.bb.TheService.theFunction:input_type -> buoyantio.bb.TheRequest + 1, // 1: buoyantio.bb.TheService.theFunction:output_type -> buoyantio.bb.TheResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } -func _TheService_TheFunction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TheRequest) - if err := dec(in); err != nil { - return nil, err +func init() { file_api_proto_init() } +func file_api_proto_init() { + if File_api_proto != nil { + return } - if interceptor == nil { - return srv.(TheServiceServer).TheFunction(ctx, in) + if !protoimpl.UnsafeEnabled { + file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TheRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TheResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/buoyantio.bb.TheService/TheFunction", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TheServiceServer).TheFunction(ctx, req.(*TheRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _TheService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "buoyantio.bb.TheService", - HandlerType: (*TheServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "theFunction", - Handler: _TheService_TheFunction_Handler, + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "api.proto", -} - -func init() { proto.RegisterFile("api.proto", fileDescriptor_api_a4df1ba5ef4ed377) } - -var fileDescriptor_api_a4df1ba5ef4ed377 = []byte{ - // 161 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x49, 0x2a, 0xcd, 0xaf, 0x4c, 0xcc, 0x2b, 0xc9, 0xcc, - 0xd7, 0x4b, 0x4a, 0x52, 0xd2, 0xe1, 0xe2, 0x0a, 0xc9, 0x48, 0x0d, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, - 0x2e, 0x11, 0x92, 0xe3, 0xe2, 0x2a, 0x82, 0x30, 0x43, 0x3d, 0x5d, 0x24, 0x18, 0x15, 0x18, 0x35, - 0x38, 0x83, 0x90, 0x44, 0x94, 0xdc, 0xb9, 0xb8, 0xc1, 0xaa, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, - 0x09, 0x29, 0x17, 0x92, 0xe0, 0x62, 0x2f, 0x48, 0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x91, 0x60, 0x02, - 0x4b, 0xc2, 0xb8, 0x46, 0x41, 0x60, 0x6b, 0x83, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0x85, 0x5c, - 0xb8, 0xb8, 0x4b, 0x32, 0x52, 0xdd, 0x4a, 0xf3, 0x92, 0x4b, 0x32, 0xf3, 0xf3, 0x84, 0x24, 0xf4, - 0x90, 0x9d, 0xa8, 0x87, 0x70, 0x9f, 0x94, 0x24, 0x16, 0x19, 0x88, 0x5b, 0x94, 0x18, 0x92, 0xd8, - 0xc0, 0xfe, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xfc, 0xde, 0xd0, 0xd9, 0xec, 0x00, 0x00, - 0x00, + GoTypes: file_api_proto_goTypes, + DependencyIndexes: file_api_proto_depIdxs, + MessageInfos: file_api_proto_msgTypes, + }.Build() + File_api_proto = out.File + file_api_proto_rawDesc = nil + file_api_proto_goTypes = nil + file_api_proto_depIdxs = nil } diff --git a/gen/api_grpc.pb.go b/gen/api_grpc.pb.go new file mode 100644 index 0000000..3de94f1 --- /dev/null +++ b/gen/api_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.20.1 +// source: api.proto + +package gen + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + TheService_TheFunction_FullMethodName = "/buoyantio.bb.TheService/theFunction" +) + +// TheServiceClient is the client API for TheService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type TheServiceClient interface { + TheFunction(ctx context.Context, in *TheRequest, opts ...grpc.CallOption) (*TheResponse, error) +} + +type theServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewTheServiceClient(cc grpc.ClientConnInterface) TheServiceClient { + return &theServiceClient{cc} +} + +func (c *theServiceClient) TheFunction(ctx context.Context, in *TheRequest, opts ...grpc.CallOption) (*TheResponse, error) { + out := new(TheResponse) + err := c.cc.Invoke(ctx, TheService_TheFunction_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// TheServiceServer is the server API for TheService service. +// All implementations must embed UnimplementedTheServiceServer +// for forward compatibility +type TheServiceServer interface { + TheFunction(context.Context, *TheRequest) (*TheResponse, error) + mustEmbedUnimplementedTheServiceServer() +} + +// UnimplementedTheServiceServer must be embedded to have forward compatible implementations. +type UnimplementedTheServiceServer struct { +} + +func (UnimplementedTheServiceServer) TheFunction(context.Context, *TheRequest) (*TheResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TheFunction not implemented") +} +func (UnimplementedTheServiceServer) mustEmbedUnimplementedTheServiceServer() {} + +// UnsafeTheServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to TheServiceServer will +// result in compilation errors. +type UnsafeTheServiceServer interface { + mustEmbedUnimplementedTheServiceServer() +} + +func RegisterTheServiceServer(s grpc.ServiceRegistrar, srv TheServiceServer) { + s.RegisterService(&TheService_ServiceDesc, srv) +} + +func _TheService_TheFunction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TheRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TheServiceServer).TheFunction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: TheService_TheFunction_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TheServiceServer).TheFunction(ctx, req.(*TheRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// TheService_ServiceDesc is the grpc.ServiceDesc for TheService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var TheService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "buoyantio.bb.TheService", + HandlerType: (*TheServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "theFunction", + Handler: _TheService_TheFunction_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api.proto", +} diff --git a/go.mod b/go.mod index b37eaeb..c3dc367 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,22 @@ module github.com/buoyantio/bb -go 1.22.1 +go 1.22.3 require ( github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.4 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 - golang.org/x/net v0.22.0 google.golang.org/grpc v1.62.1 + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 + google.golang.org/protobuf v1.33.0 ) require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect - google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index 478d42c..8be8fbf 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/protocols/grpc.go b/protocols/grpc.go index 311f4f1..c6e33c2 100644 --- a/protocols/grpc.go +++ b/protocols/grpc.go @@ -13,6 +13,7 @@ import ( ) type theGrpcServer struct { + pb.UnimplementedTheServiceServer grpcServer *grpc.Server port int serviceHandler *service.RequestHandler diff --git a/strategies/http_egress.go b/strategies/http_egress.go index ce52f9c..59bac87 100644 --- a/strategies/http_egress.go +++ b/strategies/http_egress.go @@ -3,6 +3,7 @@ package strategies import ( "context" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -40,8 +41,13 @@ type HTTPEgressStrategy struct { // Do executes the request func (s *HTTPEgressStrategy) Do(_ context.Context, req *pb.TheRequest) (*pb.TheResponse, error) { + var body io.Reader + if s.methodToUse == http.MethodPost || s.methodToUse == http.MethodPut || s.methodToUse == http.MethodPatch { + // only POST, PUT and PATCH methods can have a body + body = strings.NewReader(req.RequestUID) + } - httpRequest, err := http.NewRequest(s.methodToUse, s.urlToInvoke, strings.NewReader(req.RequestUID)) + httpRequest, err := http.NewRequest(s.methodToUse, s.urlToInvoke, body) if err != nil { return nil, err } diff --git a/strategies/http_egress_test.go b/strategies/http_egress_test.go index a77e036..6afcf94 100644 --- a/strategies/http_egress_test.go +++ b/strategies/http_egress_test.go @@ -56,8 +56,7 @@ func TestHttpEgressStrategy(t *testing.T) { var jsonPayload map[string]interface{} json.Unmarshal([]byte(response.Payload), &jsonPayload) - // hard-code HTTPS due to https://github.com/postmanlabs/httpbin/issues/536 - expectedURL := fmt.Sprintf("https://%s/anything", expectedHost) + expectedURL := fmt.Sprintf("%s://%s/anything", protocolToTest, expectedHost) actualURL := jsonPayload["url"] if actualURL != expectedURL { t.Fatalf("Expected HTTP URL to be [%s], but got [%s]", expectedURL, actualURL) diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..23412b4 --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package tools + +import ( + // for bin/protoc-gen + _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" +)