Skip to content

Commit

Permalink
update server.tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jul 7, 2024
1 parent 4658c5a commit fd6d7b1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions protoc-gen-gripmock/server.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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 }}

0 comments on commit fd6d7b1

Please sign in to comment.