From fd6d7b119063729a1e541a1a40f19fc504712d40 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sun, 7 Jul 2024 22:08:25 +0300 Subject: [PATCH] update server.tmpl --- protoc-gen-gripmock/server.tmpl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/protoc-gen-gripmock/server.tmpl b/protoc-gen-gripmock/server.tmpl index d0efc55f..8085e476 100644 --- a/protoc-gen-gripmock/server.tmpl +++ b/protoc-gen-gripmock/server.tmpl @@ -16,9 +16,9 @@ import ( "log" "net" "net/http" - "encoding/json" "github.com/gripmock/environment" + "github.com/gripmock/json" jsonpb "google.golang.org/protobuf/encoding/protojson" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -330,9 +330,10 @@ func findStub(ctx context.Context, conf environment.Config, service, method stri } } + var buffer bytes.Buffer + // Convert the search result to JSON. - data, err := json.Marshal(searchStub.JSON200.Data) - if err != nil { + if err := json.Encode(&buffer, searchStub.JSON200.Data); err != nil { return err } @@ -352,6 +353,6 @@ func findStub(ctx context.Context, conf environment.Config, service, method stri grpc.SetHeader(ctx, mdResp) // Unmarshal the search result into the output message. - return jsonpb.Unmarshal(data, out) + return jsonpb.Unmarshal(buffer.Bytes(), out) } {{ end }}