Skip to content

Commit

Permalink
try update server.tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jul 18, 2024
1 parent d80b665 commit a4d1a13
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,8 +16,8 @@ import (
"log"
"net"
"net/http"
"encoding/json"

gmjson "github.com/gripmock/json"
jsonpb "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -324,9 +324,10 @@ func findStub(ctx context.Context, addr string, service, method string, md metad
}
}

var buffer bytes.Buffer

// Convert the search result to JSON.
data, err := json.Marshal(searchStub.JSON200.Data)
if err != nil {
if err := gmjson.Encode(&buffer, searchStub.JSON200.Data); err != nil {
return err
}

Expand All @@ -346,6 +347,6 @@ func findStub(ctx context.Context, addr string, service, method string, md metad
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 a4d1a13

Please sign in to comment.