diff --git a/Makefile b/Makefile index bda2b2452..8056e1280 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,12 @@ PROTO_GOS := $(patsubst %.proto,%.pb.go,$(PROTO_DEFS)) # Download the proper protoc version for Darwin (osx) and Linux. # If you need windows for some reason it's at https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-win32.zip UNAME_S := $(shell uname -s) -PROTO_PATH := https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/ +PROTO_PATH := https://github.com/protocolbuffers/protobuf/releases/download/v29.0/ ifeq ($(UNAME_S), Linux) - PROTO_ZIP=protoc-3.6.1-linux-x86_64.zip + PROTO_ZIP= protoc-29.0-linux-x86_64.zip endif ifeq ($(UNAME_S), Darwin) - PROTO_ZIP=protoc-3.6.1-osx-x86_64.zip + PROTO_ZIP= protoc-29.0-linux-x86_64.zip endif GO_MODS=$(shell find . $(DONT_FIND) -type f -name 'go.mod' -print) @@ -65,8 +65,20 @@ clean-protos: ## Removes the proto files .PHONY: protos protos: .tools/bin/protoc .tools/bin/protoc-gen-gogoslick .tools/bin/protoc-gen-go $(PROTO_GOS) ## Creates proto files -%.pb.go: - .tools/protoc/bin/protoc -I $(GOPATH):./vendor/github.com/gogo/protobuf:./vendor:./$(@D) --gogoslick_out=plugins=grpc,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,:./$(@D) ./$(patsubst %.pb.go,%.proto,$@) +PROTO_DEFS_CSPROTO := ./httpgrpc/httpgrpc.proto +.PHONY: protos-csproto +protos-csproto: + @for name in $(PROTO_DEFS_CSPROTO); do \ + .tools/protoc/bin/protoc \ + -I . \ + --go_out=paths=source_relative:. \ + --fastmarshal_out=apiversion=v2,paths=source_relative:. \ + --go-grpc_out=require_unimplemented_servers=false,paths=source_relative:. \ + $${name}; \ + done + +#%.pb.go: +# .tools/protoc/bin/protoc -I $(GOPATH):./vendor/github.com/gogo/protobuf:./vendor:./$(@D) --gogoslick_out=plugins=grpc,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,:./$(@D) ./$(patsubst %.pb.go,%.proto,$@) .PHONY: check-protos check-protos: clean-protos protos ## Re-generates protos and git diffs them @@ -95,4 +107,10 @@ endif GOPATH=$(CURDIR)/.tools go install github.com/gogo/protobuf/protoc-gen-gogoslick@v1.3.0 .tools/bin/protoc-gen-go: .tools - GOPATH=$(CURDIR)/.tools go install github.com/golang/protobuf/protoc-gen-go@v1.3.1 + GOPATH=$(CURDIR)/.tools go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + +.tools/bin/protoc-gen-go-grpc: .tools + GOPATH=$(CURDIR)/.tools go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest + +.tools/bin/protoc-gen-fastmarshal: .tools + GOPATH=$(CURDIR)/.tools go install github.com/CrowdStrike/csproto/cmd/protoc-gen-fastmarshal@latest diff --git a/go.mod b/go.mod index 771fc1e18..6bb4b7ffb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/grafana/dskit go 1.21 require ( + github.com/CrowdStrike/csproto v0.33.0 github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 github.com/alicebob/miniredis v2.5.0+incompatible github.com/armon/go-metrics v0.3.10 @@ -39,7 +40,7 @@ require ( github.com/prometheus/common v0.44.0 github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 github.com/sercand/kuberesolver/v5 v5.1.1 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.10.0 github.com/uber/jaeger-client-go v2.28.0+incompatible github.com/uber/jaeger-lib v2.2.0+incompatible go.etcd.io/etcd/api/v3 v3.5.0 @@ -49,9 +50,11 @@ require ( go.uber.org/goleak v1.2.0 golang.org/x/exp v0.0.0-20230321023759-10a507213a29 golang.org/x/net v0.26.0 - golang.org/x/sync v0.7.0 + golang.org/x/sync v0.8.0 golang.org/x/time v0.1.0 + google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 google.golang.org/grpc v1.65.0 + google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -87,19 +90,17 @@ require ( github.com/onsi/gomega v1.24.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect - github.com/stretchr/objx v0.5.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/protobuf v1.34.1 // indirect ) replace k8s.io/client-go v12.0.0+incompatible => k8s.io/client-go v0.21.4 diff --git a/go.sum b/go.sum index 4a1cb572c..d44494327 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/CrowdStrike/csproto v0.33.0 h1:xdGHWB/WFcAwV1OmxCSOkoUcRrQRc3fDDKcKRCN0Zlg= +github.com/CrowdStrike/csproto v0.33.0/go.mod h1:quhKDsPpKaXwLWgG5xvW47QCtlmV41of4gRmMZrSxEs= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -318,18 +320,15 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber/jaeger-client-go v2.28.0+incompatible h1:G4QSBfvPKvg5ZM2j9MrJFdfI5iSljY/WnJqOGFao6HI= github.com/uber/jaeger-client-go v2.28.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= @@ -362,8 +361,8 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -418,8 +417,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -457,8 +456,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -469,8 +468,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -525,8 +524,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/grpcutil/status.go b/grpcutil/status.go index a9e9aab24..1b21ef4d6 100644 --- a/grpcutil/status.go +++ b/grpcutil/status.go @@ -35,6 +35,22 @@ func ErrorToStatus(err error) (*status.Status, bool) { return nil, false } +func ErrorToGRPCStatus(err error) (*grpcstatus.Status, bool) { + if err == nil { + return nil, false + } + type grpcStatus interface{ GRPCStatus() *grpcstatus.Status } + var gs grpcStatus + if errors.As(err, &gs) { + st := gs.GRPCStatus() + if st == nil { + return nil, false + } + return st, true + } + return nil, false +} + // ErrorToStatusCode extracts gRPC status code from error and returns it. // // - If err is nil, codes.OK is returned. diff --git a/httpgrpc/httpgrpc.go b/httpgrpc/httpgrpc.go index 616023899..a7a250ca7 100644 --- a/httpgrpc/httpgrpc.go +++ b/httpgrpc/httpgrpc.go @@ -8,14 +8,15 @@ import ( "bytes" "context" "fmt" + "io" "net/http" "github.com/go-kit/log/level" - spb "github.com/gogo/googleapis/google/rpc" - "github.com/gogo/protobuf/types" - "github.com/gogo/status" + spb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/anypb" "github.com/grafana/dskit/grpcutil" "github.com/grafana/dskit/log" @@ -131,7 +132,7 @@ func ErrorFromHTTPResponse(resp *HTTPResponse) error { // ErrorFromHTTPResponseWithMessage converts an HTTP response into a grpc error, and uses supplied message for Error message. func ErrorFromHTTPResponseWithMessage(resp *HTTPResponse, msg string) error { - a, err := types.MarshalAny(resp) + a, err := anypb.New(resp) if err != nil { return err } @@ -139,13 +140,13 @@ func ErrorFromHTTPResponseWithMessage(resp *HTTPResponse, msg string) error { return status.ErrorProto(&spb.Status{ Code: resp.Code, Message: msg, - Details: []*types.Any{a}, + Details: []*anypb.Any{a}, }) } // HTTPResponseFromError converts a grpc error into an HTTP response func HTTPResponseFromError(err error) (*HTTPResponse, bool) { - s, ok := grpcutil.ErrorToStatus(err) + s, ok := grpcutil.ErrorToGRPCStatus(err) if !ok { return nil, false } @@ -156,7 +157,7 @@ func HTTPResponseFromError(err error) (*HTTPResponse, bool) { } var resp HTTPResponse - if err := types.UnmarshalAny(status.Details[0], &resp); err != nil { + if err := status.Details[0].UnmarshalTo(&resp); err != nil { level.Error(log.Global()).Log("msg", "got error containing non-response", "err", err) return nil, false } diff --git a/httpgrpc/httpgrpc.pb.fm.go b/httpgrpc/httpgrpc.pb.fm.go new file mode 100644 index 000000000..bdc25f2b7 --- /dev/null +++ b/httpgrpc/httpgrpc.pb.fm.go @@ -0,0 +1,417 @@ +// GENERATED CODE - DO NOT EDIT +// This file was generated by protoc-gen-fastmarshal + +package httpgrpc + +import ( + "fmt" + "sync/atomic" + "github.com/CrowdStrike/csproto" +) + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for HTTPRequest + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *HTTPRequest) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Method (string,optional) + if l = len(m.Method); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + // Url (string,optional) + if l = len(m.Url); l > 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(l)) + l + } + // Headers (message,repeated) + for _, val := range m.Headers { + if l = csproto.Size(val); l > 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(l)) + l + } + } + // Body (bytes,optional) + if l = len(m.Body); l > 0 { + sz += csproto.SizeOfTagKey(4) + csproto.SizeOfVarint(uint64(l)) + l + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *HTTPRequest) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *HTTPRequest) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Method (1,string,optional) + if len(m.Method) > 0 { + enc.EncodeString(1, m.Method) + } + // Url (2,string,optional) + if len(m.Url) > 0 { + enc.EncodeString(2, m.Url) + } + // Headers (3,message,repeated) + for _, mm := range m.Headers { + if err = enc.EncodeNested(3, mm); err != nil { + return fmt.Errorf("unable to encode message data for field 'headers' (tag=3): %w", err) + } + } + // Body (4,bytes,optional) + if len(m.Body) > 0 { + enc.EncodeBytes(4, m.Body) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *HTTPRequest) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Method (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'method' (tag=1), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'method' (tag=1): %w", err) + } else { + m.Method = s + } + + case 2: // Url (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'url' (tag=2), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'url' (tag=2): %w", err) + } else { + m.Url = s + } + + case 3: // Headers (message,repeated) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'headers' (tag=3), expected 2 (length-delimited)", wt) + } + var mm Header + if err = dec.DecodeNested(&mm); err != nil { + return fmt.Errorf("unable to decode message value for field 'headers' (tag=3): %w", err) + } + m.Headers = append(m.Headers, &mm) + case 4: // Body (bytes,optional) + + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'body' (tag=4), expected 2 (length-delimited)", wt) + } + if b, err := dec.DecodeBytes(); err != nil { + return fmt.Errorf("unable to decode bytes value for field 'body' (tag=4): %w", err) + } else { + m.Body = b + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for HTTPResponse + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *HTTPResponse) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Code (int32,optional) + if m.Code != 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(m.Code)) + } + // Headers (message,repeated) + for _, val := range m.Headers { + if l = csproto.Size(val); l > 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(l)) + l + } + } + // Body (bytes,optional) + if l = len(m.Body); l > 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(l)) + l + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *HTTPResponse) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *HTTPResponse) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Code (1,int32,optional) + if m.Code != 0 { + enc.EncodeInt32(1, m.Code) + } + // Headers (2,message,repeated) + for _, mm := range m.Headers { + if err = enc.EncodeNested(2, mm); err != nil { + return fmt.Errorf("unable to encode message data for field 'headers' (tag=2): %w", err) + } + } + // Body (3,bytes,optional) + if len(m.Body) > 0 { + enc.EncodeBytes(3, m.Body) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *HTTPResponse) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Code (int32,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'Code' (tag=1), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 value for field 'Code' (tag=1): %w", err) + } else { + m.Code = v + } + case 2: // Headers (message,repeated) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'headers' (tag=2), expected 2 (length-delimited)", wt) + } + var mm Header + if err = dec.DecodeNested(&mm); err != nil { + return fmt.Errorf("unable to decode message value for field 'headers' (tag=2): %w", err) + } + m.Headers = append(m.Headers, &mm) + case 3: // Body (bytes,optional) + + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'body' (tag=3), expected 2 (length-delimited)", wt) + } + if b, err := dec.DecodeBytes(); err != nil { + return fmt.Errorf("unable to decode bytes value for field 'body' (tag=3): %w", err) + } else { + m.Body = b + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for Header + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *Header) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Key (string,optional) + if l = len(m.Key); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + // Values (string,repeated) + for _, sv := range m.Values { + l = len(sv) + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(l)) + l + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *Header) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *Header) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Key (1,string,optional) + if len(m.Key) > 0 { + enc.EncodeString(1, m.Key) + } + // Values (2,string,repeated) + for _, val := range m.Values { + enc.EncodeString(2, val) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *Header) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Key (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'key' (tag=1), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'key' (tag=1): %w", err) + } else { + m.Key = s + } + + case 2: // Values (string,repeated) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'values' (tag=2), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'values' (tag=2): %w", err) + } else { + m.Values = append(m.Values, s) + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} diff --git a/httpgrpc/httpgrpc.pb.go b/httpgrpc/httpgrpc.pb.go index bab0efd53..f8fee38c1 100644 --- a/httpgrpc/httpgrpc.pb.go +++ b/httpgrpc/httpgrpc.pb.go @@ -1,1311 +1,288 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: httpgrpc.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.0 +// protoc v5.29.0 +// source: httpgrpc/httpgrpc.proto package httpgrpc import ( - bytes "bytes" - context "context" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" - strings "strings" + 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.GoGoProtoPackageIsVersion3 // 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 HTTPRequest struct { - Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` - Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` - Headers []*Header `protobuf:"bytes,3,rep,name=headers,proto3" json:"headers,omitempty"` - Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` -} - -func (m *HTTPRequest) Reset() { *m = HTTPRequest{} } -func (*HTTPRequest) ProtoMessage() {} -func (*HTTPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c50820dbc814fcdd, []int{0} -} -func (m *HTTPRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HTTPRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HTTPRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HTTPRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_HTTPRequest.Merge(m, src) -} -func (m *HTTPRequest) XXX_Size() int { - return m.Size() -} -func (m *HTTPRequest) XXX_DiscardUnknown() { - xxx_messageInfo_HTTPRequest.DiscardUnknown(m) + state protoimpl.MessageState `protogen:"open.v1"` + Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` + Headers []*Header `protobuf:"bytes,3,rep,name=headers,proto3" json:"headers,omitempty"` + Body []byte `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -var xxx_messageInfo_HTTPRequest proto.InternalMessageInfo - -func (m *HTTPRequest) GetMethod() string { - if m != nil { - return m.Method - } - return "" -} - -func (m *HTTPRequest) GetUrl() string { - if m != nil { - return m.Url - } - return "" +func (x *HTTPRequest) Reset() { + *x = HTTPRequest{} + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *HTTPRequest) GetHeaders() []*Header { - if m != nil { - return m.Headers - } - return nil -} - -func (m *HTTPRequest) GetBody() []byte { - if m != nil { - return m.Body - } - return nil +func (x *HTTPRequest) String() string { + return protoimpl.X.MessageStringOf(x) } -type HTTPResponse struct { - Code int32 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"` - Headers []*Header `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"` - Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` -} +func (*HTTPRequest) ProtoMessage() {} -func (m *HTTPResponse) Reset() { *m = HTTPResponse{} } -func (*HTTPResponse) ProtoMessage() {} -func (*HTTPResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c50820dbc814fcdd, []int{1} -} -func (m *HTTPResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HTTPResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HTTPResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (x *HTTPRequest) ProtoReflect() protoreflect.Message { + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil - } -} -func (m *HTTPResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_HTTPResponse.Merge(m, src) -} -func (m *HTTPResponse) XXX_Size() int { - return m.Size() -} -func (m *HTTPResponse) XXX_DiscardUnknown() { - xxx_messageInfo_HTTPResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_HTTPResponse proto.InternalMessageInfo - -func (m *HTTPResponse) GetCode() int32 { - if m != nil { - return m.Code + return ms } - return 0 + return mi.MessageOf(x) } -func (m *HTTPResponse) GetHeaders() []*Header { - if m != nil { - return m.Headers - } - return nil -} - -func (m *HTTPResponse) GetBody() []byte { - if m != nil { - return m.Body - } - return nil -} - -type Header struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` +// Deprecated: Use HTTPRequest.ProtoReflect.Descriptor instead. +func (*HTTPRequest) Descriptor() ([]byte, []int) { + return file_httpgrpc_httpgrpc_proto_rawDescGZIP(), []int{0} } -func (m *Header) Reset() { *m = Header{} } -func (*Header) ProtoMessage() {} -func (*Header) Descriptor() ([]byte, []int) { - return fileDescriptor_c50820dbc814fcdd, []int{2} -} -func (m *Header) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Header.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil +func (x *HTTPRequest) GetMethod() string { + if x != nil { + return x.Method } + return "" } -func (m *Header) XXX_Merge(src proto.Message) { - xxx_messageInfo_Header.Merge(m, src) -} -func (m *Header) XXX_Size() int { - return m.Size() -} -func (m *Header) XXX_DiscardUnknown() { - xxx_messageInfo_Header.DiscardUnknown(m) -} - -var xxx_messageInfo_Header proto.InternalMessageInfo -func (m *Header) GetKey() string { - if m != nil { - return m.Key +func (x *HTTPRequest) GetUrl() string { + if x != nil { + return x.Url } return "" } -func (m *Header) GetValues() []string { - if m != nil { - return m.Values +func (x *HTTPRequest) GetHeaders() []*Header { + if x != nil { + return x.Headers } return nil } -func init() { - proto.RegisterType((*HTTPRequest)(nil), "httpgrpc.HTTPRequest") - proto.RegisterType((*HTTPResponse)(nil), "httpgrpc.HTTPResponse") - proto.RegisterType((*Header)(nil), "httpgrpc.Header") -} - -func init() { proto.RegisterFile("httpgrpc.proto", fileDescriptor_c50820dbc814fcdd) } - -var fileDescriptor_c50820dbc814fcdd = []byte{ - // 301 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xbd, 0x4e, 0xc3, 0x30, - 0x14, 0x85, 0xed, 0xa6, 0x04, 0xea, 0x56, 0xa8, 0xb2, 0xa0, 0x8a, 0x3a, 0x5c, 0x55, 0x99, 0x22, - 0x86, 0x22, 0x05, 0x16, 0x46, 0x60, 0xc9, 0x88, 0xac, 0xbe, 0x40, 0x42, 0xac, 0x44, 0x22, 0xd4, - 0x21, 0x3f, 0xa0, 0x6e, 0x3c, 0x02, 0x8f, 0xc1, 0xa3, 0x30, 0x66, 0xec, 0x48, 0x9c, 0x85, 0xb1, - 0x8f, 0x80, 0xec, 0xa4, 0x10, 0x31, 0xb1, 0x9d, 0x7b, 0xee, 0x51, 0xbe, 0x7b, 0x62, 0x72, 0x1c, - 0x17, 0x45, 0x1a, 0x65, 0xe9, 0xfd, 0x32, 0xcd, 0x44, 0x21, 0xe8, 0xd1, 0x7e, 0x9e, 0x9f, 0x44, - 0x22, 0x12, 0xda, 0x3c, 0x57, 0xaa, 0xdd, 0xdb, 0x2f, 0x64, 0xec, 0xad, 0x56, 0x77, 0x8c, 0x3f, - 0x95, 0x3c, 0x2f, 0xe8, 0x8c, 0x98, 0x8f, 0xbc, 0x88, 0x45, 0x68, 0xe1, 0x05, 0x76, 0x46, 0xac, - 0x9b, 0xe8, 0x94, 0x18, 0x65, 0x96, 0x58, 0x03, 0x6d, 0x2a, 0x49, 0xcf, 0xc8, 0x61, 0xcc, 0xfd, - 0x90, 0x67, 0xb9, 0x65, 0x2c, 0x0c, 0x67, 0xec, 0x4e, 0x97, 0x3f, 0x68, 0x4f, 0x2f, 0xd8, 0x3e, - 0x40, 0x29, 0x19, 0x06, 0x22, 0xdc, 0x58, 0xc3, 0x05, 0x76, 0x26, 0x4c, 0x6b, 0x3b, 0x20, 0x93, - 0x16, 0x9c, 0xa7, 0x62, 0x9d, 0x73, 0x95, 0xb9, 0x15, 0x21, 0xd7, 0xdc, 0x03, 0xa6, 0x75, 0x9f, - 0x31, 0xf8, 0x2f, 0xc3, 0xe8, 0x31, 0x5c, 0x62, 0xb6, 0x31, 0x75, 0xff, 0x03, 0xdf, 0x74, 0xa5, - 0x94, 0x54, 0x4d, 0x9f, 0xfd, 0xa4, 0xe4, 0xed, 0xa7, 0x47, 0xac, 0x9b, 0xdc, 0x6b, 0x32, 0x54, - 0x77, 0xd1, 0x2b, 0x62, 0x7a, 0xfe, 0x3a, 0x4c, 0x38, 0x3d, 0xed, 0x41, 0x7f, 0x7f, 0xd5, 0x7c, - 0xf6, 0xd7, 0x6e, 0x8b, 0xd8, 0xe8, 0xe6, 0xb2, 0xaa, 0x01, 0x6d, 0x6b, 0x40, 0xbb, 0x1a, 0xf0, - 0xab, 0x04, 0xfc, 0x2e, 0x01, 0x7f, 0x48, 0xc0, 0x95, 0x04, 0xfc, 0x29, 0x01, 0x7f, 0x49, 0x40, - 0x3b, 0x09, 0xf8, 0xad, 0x01, 0x54, 0x35, 0x80, 0xb6, 0x0d, 0xa0, 0xc0, 0xd4, 0x0f, 0x72, 0xf1, - 0x1d, 0x00, 0x00, 0xff, 0xff, 0x44, 0x0e, 0x7c, 0xff, 0xc2, 0x01, 0x00, 0x00, -} - -func (this *HTTPRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HTTPRequest) - if !ok { - that2, ok := that.(HTTPRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Method != that1.Method { - return false - } - if this.Url != that1.Url { - return false - } - if len(this.Headers) != len(that1.Headers) { - return false - } - for i := range this.Headers { - if !this.Headers[i].Equal(that1.Headers[i]) { - return false - } - } - if !bytes.Equal(this.Body, that1.Body) { - return false - } - return true -} -func (this *HTTPResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*HTTPResponse) - if !ok { - that2, ok := that.(HTTPResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Code != that1.Code { - return false - } - if len(this.Headers) != len(that1.Headers) { - return false - } - for i := range this.Headers { - if !this.Headers[i].Equal(that1.Headers[i]) { - return false - } - } - if !bytes.Equal(this.Body, that1.Body) { - return false - } - return true -} -func (this *Header) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Header) - if !ok { - that2, ok := that.(Header) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Key != that1.Key { - return false - } - if len(this.Values) != len(that1.Values) { - return false +func (x *HTTPRequest) GetBody() []byte { + if x != nil { + return x.Body } - for i := range this.Values { - if this.Values[i] != that1.Values[i] { - return false - } - } - return true -} -func (this *HTTPRequest) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 8) - s = append(s, "&httpgrpc.HTTPRequest{") - s = append(s, "Method: "+fmt.Sprintf("%#v", this.Method)+",\n") - s = append(s, "Url: "+fmt.Sprintf("%#v", this.Url)+",\n") - if this.Headers != nil { - s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") - } - s = append(s, "Body: "+fmt.Sprintf("%#v", this.Body)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *HTTPResponse) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 7) - s = append(s, "&httpgrpc.HTTPResponse{") - s = append(s, "Code: "+fmt.Sprintf("%#v", this.Code)+",\n") - if this.Headers != nil { - s = append(s, "Headers: "+fmt.Sprintf("%#v", this.Headers)+",\n") - } - s = append(s, "Body: "+fmt.Sprintf("%#v", this.Body)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *Header) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&httpgrpc.Header{") - s = append(s, "Key: "+fmt.Sprintf("%#v", this.Key)+",\n") - s = append(s, "Values: "+fmt.Sprintf("%#v", this.Values)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringHttpgrpc(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} - -// 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 - -// HTTPClient is the client API for HTTP service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type HTTPClient interface { - Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) -} - -type hTTPClient struct { - cc *grpc.ClientConn -} - -func NewHTTPClient(cc *grpc.ClientConn) HTTPClient { - return &hTTPClient{cc} -} - -func (c *hTTPClient) Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) { - out := new(HTTPResponse) - err := c.cc.Invoke(ctx, "/httpgrpc.HTTP/Handle", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// HTTPServer is the server API for HTTP service. -type HTTPServer interface { - Handle(context.Context, *HTTPRequest) (*HTTPResponse, error) + return nil } -// UnimplementedHTTPServer can be embedded to have forward compatible implementations. -type UnimplementedHTTPServer struct { +type HTTPResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Code int32 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"` + Headers []*Header `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"` + Body []byte `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (*UnimplementedHTTPServer) Handle(ctx context.Context, req *HTTPRequest) (*HTTPResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented") +func (x *HTTPResponse) Reset() { + *x = HTTPResponse{} + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func RegisterHTTPServer(s *grpc.Server, srv HTTPServer) { - s.RegisterService(&_HTTP_serviceDesc, srv) +func (x *HTTPResponse) String() string { + return protoimpl.X.MessageStringOf(x) } -func _HTTP_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HTTPRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(HTTPServer).Handle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/httpgrpc.HTTP/Handle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HTTPServer).Handle(ctx, req.(*HTTPRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _HTTP_serviceDesc = grpc.ServiceDesc{ - ServiceName: "httpgrpc.HTTP", - HandlerType: (*HTTPServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Handle", - Handler: _HTTP_Handle_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "httpgrpc.proto", -} +func (*HTTPResponse) ProtoMessage() {} -func (m *HTTPRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (x *HTTPResponse) ProtoReflect() protoreflect.Message { + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - return dAtA[:n], nil + return mi.MessageOf(x) } -func (m *HTTPRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +// Deprecated: Use HTTPResponse.ProtoReflect.Descriptor instead. +func (*HTTPResponse) Descriptor() ([]byte, []int) { + return file_httpgrpc_httpgrpc_proto_rawDescGZIP(), []int{1} } -func (m *HTTPRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Body) > 0 { - i -= len(m.Body) - copy(dAtA[i:], m.Body) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Body))) - i-- - dAtA[i] = 0x22 - } - if len(m.Headers) > 0 { - for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintHttpgrpc(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.Url) > 0 { - i -= len(m.Url) - copy(dAtA[i:], m.Url) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Url))) - i-- - dAtA[i] = 0x12 - } - if len(m.Method) > 0 { - i -= len(m.Method) - copy(dAtA[i:], m.Method) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Method))) - i-- - dAtA[i] = 0xa +func (x *HTTPResponse) GetCode() int32 { + if x != nil { + return x.Code } - return len(dAtA) - i, nil + return 0 } -func (m *HTTPResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (x *HTTPResponse) GetHeaders() []*Header { + if x != nil { + return x.Headers } - return dAtA[:n], nil -} - -func (m *HTTPResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) + return nil } -func (m *HTTPResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Body) > 0 { - i -= len(m.Body) - copy(dAtA[i:], m.Body) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Body))) - i-- - dAtA[i] = 0x1a - } - if len(m.Headers) > 0 { - for iNdEx := len(m.Headers) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Headers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintHttpgrpc(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } +func (x *HTTPResponse) GetBody() []byte { + if x != nil { + return x.Body } - if m.Code != 0 { - i = encodeVarintHttpgrpc(dAtA, i, uint64(m.Code)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil + return nil } -func (m *Header) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil +type Header struct { + state protoimpl.MessageState `protogen:"open.v1"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *Header) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +func (x *Header) Reset() { + *x = Header{} + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Values) > 0 { - for iNdEx := len(m.Values) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Values[iNdEx]) - copy(dAtA[i:], m.Values[iNdEx]) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Values[iNdEx]))) - i-- - dAtA[i] = 0x12 - } - } - if len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintHttpgrpc(dAtA, i, uint64(len(m.Key))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil +func (x *Header) String() string { + return protoimpl.X.MessageStringOf(x) } -func encodeVarintHttpgrpc(dAtA []byte, offset int, v uint64) int { - offset -= sovHttpgrpc(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *HTTPRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Method) - if l > 0 { - n += 1 + l + sovHttpgrpc(uint64(l)) - } - l = len(m.Url) - if l > 0 { - n += 1 + l + sovHttpgrpc(uint64(l)) - } - if len(m.Headers) > 0 { - for _, e := range m.Headers { - l = e.Size() - n += 1 + l + sovHttpgrpc(uint64(l)) - } - } - l = len(m.Body) - if l > 0 { - n += 1 + l + sovHttpgrpc(uint64(l)) - } - return n -} +func (*Header) ProtoMessage() {} -func (m *HTTPResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Code != 0 { - n += 1 + sovHttpgrpc(uint64(m.Code)) - } - if len(m.Headers) > 0 { - for _, e := range m.Headers { - l = e.Size() - n += 1 + l + sovHttpgrpc(uint64(l)) +func (x *Header) ProtoReflect() protoreflect.Message { + mi := &file_httpgrpc_httpgrpc_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } + return ms } - l = len(m.Body) - if l > 0 { - n += 1 + l + sovHttpgrpc(uint64(l)) - } - return n + return mi.MessageOf(x) } -func (m *Header) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovHttpgrpc(uint64(l)) - } - if len(m.Values) > 0 { - for _, s := range m.Values { - l = len(s) - n += 1 + l + sovHttpgrpc(uint64(l)) - } - } - return n +// Deprecated: Use Header.ProtoReflect.Descriptor instead. +func (*Header) Descriptor() ([]byte, []int) { + return file_httpgrpc_httpgrpc_proto_rawDescGZIP(), []int{2} } -func sovHttpgrpc(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozHttpgrpc(x uint64) (n int) { - return sovHttpgrpc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *HTTPRequest) String() string { - if this == nil { - return "nil" - } - repeatedStringForHeaders := "[]*Header{" - for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(f.String(), "Header", "Header", 1) + "," - } - repeatedStringForHeaders += "}" - s := strings.Join([]string{`&HTTPRequest{`, - `Method:` + fmt.Sprintf("%v", this.Method) + `,`, - `Url:` + fmt.Sprintf("%v", this.Url) + `,`, - `Headers:` + repeatedStringForHeaders + `,`, - `Body:` + fmt.Sprintf("%v", this.Body) + `,`, - `}`, - }, "") - return s -} -func (this *HTTPResponse) String() string { - if this == nil { - return "nil" - } - repeatedStringForHeaders := "[]*Header{" - for _, f := range this.Headers { - repeatedStringForHeaders += strings.Replace(f.String(), "Header", "Header", 1) + "," - } - repeatedStringForHeaders += "}" - s := strings.Join([]string{`&HTTPResponse{`, - `Code:` + fmt.Sprintf("%v", this.Code) + `,`, - `Headers:` + repeatedStringForHeaders + `,`, - `Body:` + fmt.Sprintf("%v", this.Body) + `,`, - `}`, - }, "") - return s -} -func (this *Header) String() string { - if this == nil { - return "nil" +func (x *Header) GetKey() string { + if x != nil { + return x.Key } - s := strings.Join([]string{`&Header{`, - `Key:` + fmt.Sprintf("%v", this.Key) + `,`, - `Values:` + fmt.Sprintf("%v", this.Values) + `,`, - `}`, - }, "") - return s -} -func valueToStringHttpgrpc(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *HTTPRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HTTPRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HTTPRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Method", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Method = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Url", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Url = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Headers = append(m.Headers, &Header{}) - if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Body = append(m.Body[:0], dAtA[iNdEx:postIndex]...) - if m.Body == nil { - m.Body = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHttpgrpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil + return "" } -func (m *HTTPResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HTTPResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HTTPResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Code", wireType) - } - m.Code = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Code |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Headers = append(m.Headers, &Header{}) - if err := m.Headers[len(m.Headers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Body = append(m.Body[:0], dAtA[iNdEx:postIndex]...) - if m.Body == nil { - m.Body = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHttpgrpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF +func (x *Header) GetValues() []string { + if x != nil { + return x.Values } return nil } -func (m *Header) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Header: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Header: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Values", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthHttpgrpc - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthHttpgrpc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Values = append(m.Values, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipHttpgrpc(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipHttpgrpc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthHttpgrpc - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthHttpgrpc - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipHttpgrpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthHttpgrpc - } - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") +var File_httpgrpc_httpgrpc_proto protoreflect.FileDescriptor + +var file_httpgrpc_httpgrpc_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x67, + 0x72, 0x70, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x68, 0x74, 0x74, 0x70, 0x67, + 0x72, 0x70, 0x63, 0x22, 0x77, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, + 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x2a, 0x0a, 0x07, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, + 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x62, 0x0a, 0x0c, + 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, + 0x12, 0x2a, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, 0x04, + 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x22, 0x32, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x73, 0x32, 0x41, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, 0x39, 0x0a, 0x06, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12, 0x15, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x64, 0x73, + 0x6b, 0x69, 0x74, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( - ErrInvalidLengthHttpgrpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowHttpgrpc = fmt.Errorf("proto: integer overflow") + file_httpgrpc_httpgrpc_proto_rawDescOnce sync.Once + file_httpgrpc_httpgrpc_proto_rawDescData = file_httpgrpc_httpgrpc_proto_rawDesc ) + +func file_httpgrpc_httpgrpc_proto_rawDescGZIP() []byte { + file_httpgrpc_httpgrpc_proto_rawDescOnce.Do(func() { + file_httpgrpc_httpgrpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_httpgrpc_httpgrpc_proto_rawDescData) + }) + return file_httpgrpc_httpgrpc_proto_rawDescData +} + +var file_httpgrpc_httpgrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_httpgrpc_httpgrpc_proto_goTypes = []any{ + (*HTTPRequest)(nil), // 0: httpgrpc.HTTPRequest + (*HTTPResponse)(nil), // 1: httpgrpc.HTTPResponse + (*Header)(nil), // 2: httpgrpc.Header +} +var file_httpgrpc_httpgrpc_proto_depIdxs = []int32{ + 2, // 0: httpgrpc.HTTPRequest.headers:type_name -> httpgrpc.Header + 2, // 1: httpgrpc.HTTPResponse.headers:type_name -> httpgrpc.Header + 0, // 2: httpgrpc.HTTP.Handle:input_type -> httpgrpc.HTTPRequest + 1, // 3: httpgrpc.HTTP.Handle:output_type -> httpgrpc.HTTPResponse + 3, // [3:4] is the sub-list for method output_type + 2, // [2:3] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_httpgrpc_httpgrpc_proto_init() } +func file_httpgrpc_httpgrpc_proto_init() { + if File_httpgrpc_httpgrpc_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_httpgrpc_httpgrpc_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_httpgrpc_httpgrpc_proto_goTypes, + DependencyIndexes: file_httpgrpc_httpgrpc_proto_depIdxs, + MessageInfos: file_httpgrpc_httpgrpc_proto_msgTypes, + }.Build() + File_httpgrpc_httpgrpc_proto = out.File + file_httpgrpc_httpgrpc_proto_rawDesc = nil + file_httpgrpc_httpgrpc_proto_goTypes = nil + file_httpgrpc_httpgrpc_proto_depIdxs = nil +} diff --git a/httpgrpc/httpgrpc.proto b/httpgrpc/httpgrpc.proto index 8f546330a..9a6db6ffa 100644 --- a/httpgrpc/httpgrpc.proto +++ b/httpgrpc/httpgrpc.proto @@ -1,16 +1,7 @@ syntax = "proto3"; package httpgrpc; - -import "gogoproto/gogo.proto"; - -option (gogoproto.equal_all) = true; -option (gogoproto.gostring_all) = true; -option (gogoproto.stringer_all) = true; -option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.goproto_unkeyed_all) = false; -option (gogoproto.goproto_unrecognized_all) = false; -option (gogoproto.goproto_sizecache_all) = false; +option go_package = "github.com/grafana/dskit/httpgrpc"; service HTTP { rpc Handle(HTTPRequest) returns (HTTPResponse) {}; diff --git a/httpgrpc/httpgrpc_grpc.pb.go b/httpgrpc/httpgrpc_grpc.pb.go new file mode 100644 index 000000000..cddfd9bc1 --- /dev/null +++ b/httpgrpc/httpgrpc_grpc.pb.go @@ -0,0 +1,119 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.29.0 +// source: httpgrpc/httpgrpc.proto + +package httpgrpc + +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.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + HTTP_Handle_FullMethodName = "/httpgrpc.HTTP/Handle" +) + +// HTTPClient is the client API for HTTP 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 HTTPClient interface { + Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) +} + +type hTTPClient struct { + cc grpc.ClientConnInterface +} + +func NewHTTPClient(cc grpc.ClientConnInterface) HTTPClient { + return &hTTPClient{cc} +} + +func (c *hTTPClient) Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(HTTPResponse) + err := c.cc.Invoke(ctx, HTTP_Handle_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// HTTPServer is the server API for HTTP service. +// All implementations should embed UnimplementedHTTPServer +// for forward compatibility. +type HTTPServer interface { + Handle(context.Context, *HTTPRequest) (*HTTPResponse, error) +} + +// UnimplementedHTTPServer should be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedHTTPServer struct{} + +func (UnimplementedHTTPServer) Handle(context.Context, *HTTPRequest) (*HTTPResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented") +} +func (UnimplementedHTTPServer) testEmbeddedByValue() {} + +// UnsafeHTTPServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to HTTPServer will +// result in compilation errors. +type UnsafeHTTPServer interface { + mustEmbedUnimplementedHTTPServer() +} + +func RegisterHTTPServer(s grpc.ServiceRegistrar, srv HTTPServer) { + // If the following call pancis, it indicates UnimplementedHTTPServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&HTTP_ServiceDesc, srv) +} + +func _HTTP_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HTTPRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HTTPServer).Handle(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: HTTP_Handle_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HTTPServer).Handle(ctx, req.(*HTTPRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// HTTP_ServiceDesc is the grpc.ServiceDesc for HTTP service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var HTTP_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "httpgrpc.HTTP", + HandlerType: (*HTTPServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Handle", + Handler: _HTTP_Handle_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "httpgrpc/httpgrpc.proto", +} diff --git a/httpgrpc/httpgrpc_grpc_benchmark_test.go b/httpgrpc/httpgrpc_grpc_benchmark_test.go new file mode 100644 index 000000000..9d8143d3b --- /dev/null +++ b/httpgrpc/httpgrpc_grpc_benchmark_test.go @@ -0,0 +1,66 @@ +package httpgrpc + +import ( + "strings" + "testing" +) + +var ( + small = &HTTPRequest{ + Method: "GET", + Url: "/test", + Body: []byte(strings.Repeat(".", 32)), + } + medium = &HTTPRequest{ + Method: "GET", + Url: "/test", + Body: []byte(strings.Repeat(".", 16*1024)), + } + large = &HTTPRequest{ + Method: "GET", + Url: "/test", + Body: []byte(strings.Repeat(".", 4*16*1024)), + } +) + +func BenchmarkCodec(b *testing.B) { + smallBytes, err := small.Marshal() + if err != nil { + b.Fatal(err) + } + + mediumBytes, err := medium.Marshal() + if err != nil { + b.Fatal(err) + } + + largeBytes, err := large.Marshal() + if err != nil { + b.Fatal(err) + } + + msgs := [][]byte{smallBytes, mediumBytes, largeBytes} + + names := []string{"sm", "md", "lg"} + b.Run("marshall-unmarshall", func(b *testing.B) { + for msgIdx, msgBytes := range msgs { + b.Run(names[msgIdx], func(b *testing.B) { + for i := 0; i < b.N; i++ { + + outputMsg := new(HTTPRequest) + err := outputMsg.Unmarshal(msgBytes) + if err != nil { + b.Fatal(err) + } + + _, err = outputMsg.Marshal() + if err != nil { + b.Fatal(err) + } + + } + }) + } + }) + +} diff --git a/httpgrpc/httpgrpc_test.go b/httpgrpc/httpgrpc_test.go index 86f3090c9..d51464244 100644 --- a/httpgrpc/httpgrpc_test.go +++ b/httpgrpc/httpgrpc_test.go @@ -4,14 +4,14 @@ import ( "context" "errors" "fmt" + "net/http" "testing" - "github.com/gogo/status" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" - grpcstatus "google.golang.org/grpc/status" + "google.golang.org/grpc/status" ) func TestAppendMessageSizeToOutgoingContext(t *testing.T) { @@ -97,7 +97,7 @@ func TestHTTPResponseFromError(t *testing.T) { err: status.Error(codes.Internal, msgErr), }, "a gRPC error built by grpc/status cannot be parsed to an HTTPResponse": { - err: grpcstatus.Error(codes.Internal, msgErr), + err: status.Error(codes.Internal, msgErr), }, "a gRPC error built by httpgrpc can be parsed to an HTTPResponse": { err: Error(400, msgErr), @@ -129,6 +129,6 @@ func checkDetailAsHTTPResponse(t *testing.T, httpResponse *HTTPResponse, stat *s require.True(t, ok) require.NotNil(t, respDetails) require.Equal(t, httpResponse.Code, respDetails.Code) - require.Equal(t, httpResponse.Headers, respDetails.Headers) + require.EqualExportedValues(t, httpResponse.Headers, respDetails.Headers) require.Equal(t, httpResponse.Body, respDetails.Body) } diff --git a/httpgrpc/init.go b/httpgrpc/init.go new file mode 100644 index 000000000..933239498 --- /dev/null +++ b/httpgrpc/init.go @@ -0,0 +1,11 @@ +package httpgrpc + +import ( + "github.com/CrowdStrike/csproto" + "google.golang.org/grpc/encoding" + _ "google.golang.org/grpc/encoding/proto" +) + +func init() { + encoding.RegisterCodec(csproto.GrpcCodec{}) +} diff --git a/ring/example/local/go.mod b/ring/example/local/go.mod index 258f22f74..4e4486364 100644 --- a/ring/example/local/go.mod +++ b/ring/example/local/go.mod @@ -11,6 +11,7 @@ require ( ) require ( + github.com/CrowdStrike/csproto v0.33.0 // indirect github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/armon/go-metrics v0.3.10 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -59,15 +60,15 @@ require ( go.uber.org/zap v1.17.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.1.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/grpc v1.66.0 // indirect - google.golang.org/protobuf v1.34.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect ) replace github.com/hashicorp/memberlist => github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe diff --git a/ring/example/local/go.sum b/ring/example/local/go.sum index 9d0fe7587..b760b0a7f 100644 --- a/ring/example/local/go.sum +++ b/ring/example/local/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/CrowdStrike/csproto v0.33.0 h1:xdGHWB/WFcAwV1OmxCSOkoUcRrQRc3fDDKcKRCN0Zlg= +github.com/CrowdStrike/csproto v0.33.0/go.mod h1:quhKDsPpKaXwLWgG5xvW47QCtlmV41of4gRmMZrSxEs= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -257,15 +259,15 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber/jaeger-client-go v2.28.0+incompatible h1:G4QSBfvPKvg5ZM2j9MrJFdfI5iSljY/WnJqOGFao6HI= github.com/uber/jaeger-client-go v2.28.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= @@ -340,8 +342,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -373,16 +375,16 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -435,8 +437,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/server/server_test.go b/server/server_test.go index d5390e7aa..a0b291319 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -206,6 +206,7 @@ func TestErrorInstrumentationMiddleware(t *testing.T) { client := NewFakeServerClient(conn) res, err := client.Succeed(context.Background(), &empty) require.NoError(t, err) + empty.Reset() // reset request to compare with the response, which will not have sizeCache=1 require.EqualValues(t, &empty, res) res, err = client.FailWithError(context.Background(), &empty) @@ -618,6 +619,7 @@ func TestTLSServer(t *testing.T) { grpcClient := NewFakeServerClient(conn) grpcRes, err := grpcClient.Succeed(context.Background(), &empty) require.NoError(t, err) + empty.Reset() // reset request to compare with the response, which will not have sizeCache=1 require.EqualValues(t, &empty, grpcRes) } @@ -709,6 +711,7 @@ func TestTLSServerWithInlineCerts(t *testing.T) { grpcClient := NewFakeServerClient(conn) grpcRes, err := grpcClient.Succeed(context.Background(), &empty) require.NoError(t, err) + empty.Reset() // reset request to compare with the response, which will not have sizeCache=1 require.EqualValues(t, &empty, grpcRes) }