From 0e24395996b57ab49e025d2bca7a98d2a02cf83b Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 2 Sep 2023 10:26:07 +0300 Subject: [PATCH 1/2] gzip encoding support --- example/simple/client/main.go | 11 +++++++++++ protoc-gen-gripmock/server.tmpl | 1 + 2 files changed, 12 insertions(+) diff --git a/example/simple/client/main.go b/example/simple/client/main.go index b5f14c54..14ea3cd0 100644 --- a/example/simple/client/main.go +++ b/example/simple/client/main.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/encoding/gzip" "google.golang.org/grpc/status" pb "github.com/bavix/gripmock/protogen/example/simple" @@ -72,6 +73,16 @@ func main() { } log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode) + name = "simple3" + r, err = c.SayHello(context.Background(), &pb.Request{Name: name}, grpc.UseCompressor(gzip.Name)) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + if r.ReturnCode != 3 { + log.Fatalf("grpc server returned code: %d, expected code: %d", r.ReturnCode, 3) + } + log.Printf("Greeting (gzip): %s (return code %d)", r.Message, r.ReturnCode) + name = "error" r, err = c.SayHello(context.Background(), &pb.Request{Name: name}) if err == nil { diff --git a/protoc-gen-gripmock/server.tmpl b/protoc-gen-gripmock/server.tmpl index 28de9bf8..89aaebb7 100644 --- a/protoc-gen-gripmock/server.tmpl +++ b/protoc-gen-gripmock/server.tmpl @@ -19,6 +19,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + _ "google.golang.org/grpc/encoding/gzip" "github.com/bavix/gripmock/pkg/sdk" ) From 9d76e9f299f6eb820a4a7da31c60577dba2fb1f3 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 2 Sep 2023 10:27:51 +0300 Subject: [PATCH 2/2] typo fix --- pkg/yaml2json/convertor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/yaml2json/convertor.go b/pkg/yaml2json/convertor.go index c2db2854..aa66fb28 100644 --- a/pkg/yaml2json/convertor.go +++ b/pkg/yaml2json/convertor.go @@ -12,7 +12,7 @@ func New() *Convertor { return &Convertor{engine: &engine{}} } -func (t *Convertor) Execute(name string, data []byte) (res []byte, err error) { +func (t *Convertor) Execute(name string, data []byte) ([]byte, error) { bytes, err := t.engine.Execute(name, data) if err != nil { return nil, err