Skip to content

Commit

Permalink
use native json marshaling to map stubbed output (#52)
Browse files Browse the repository at this point in the history
* use native json marshaling to map stubbed output

When an output field had a '_' in its name, it was not mapped
correctly by 'mapstructure' to the protoc generated class because,
in this class, the fields are translated in CamelCase.
Hower, the fields have json tag with their original name.
Json marshalling is then the way to fix this issue.
  • Loading branch information
vincent-raman authored Aug 3, 2020
1 parent e21a586 commit 398c134
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 104 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ RUN mkdir /stubs
RUN apk -U --no-cache add git protobuf

RUN go get -u -v github.com/golang/protobuf/protoc-gen-go \
github.com/mitchellh/mapstructure \
google.golang.org/grpc \
google.golang.org/grpc/reflection \
golang.org/x/net/context \
Expand All @@ -16,7 +15,7 @@ RUN go get -u -v github.com/golang/protobuf/protoc-gen-go \
golang.org/x/tools/imports

RUN go get -u -v github.com/gobuffalo/packr/v2/... \
github.com/gobuffalo/packr/v2/packr2
github.com/gobuffalo/packr/v2/packr2

# cloning well-known-types
RUN git clone https://github.com/google/protobuf.git /protobuf-repo
Expand Down
2 changes: 1 addition & 1 deletion example/simple/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func main() {
if err != nil {
log.Fatalf("error from grpc: %v", err)
}
log.Printf("Greeting: %s", r.Message)
log.Printf("Greeting: %s (return code %d)", r.Message, r.ReturnCode)
}
293 changes: 204 additions & 89 deletions example/simple/simple.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/simple/simple.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ message Request {
// The response message containing the greetings
message Reply {
string message = 1;
int32 return_code = 2;
}
Loading

0 comments on commit 398c134

Please sign in to comment.