Skip to content

Commit

Permalink
Merge pull request #22 from bavix/add-support-grpc-gzip
Browse files Browse the repository at this point in the history
[2.0] gzip encoding support
  • Loading branch information
rez1dent3 authored Sep 2, 2023
2 parents 4ffacf2 + 9d76e9f commit 1b5fb78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions example/simple/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/yaml2json/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions protoc-gen-gripmock/server.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 1b5fb78

Please sign in to comment.