I found a solution which actually imposes two steps:
1. hook on the generated gateway forwarding methods to flag certain data to
convert to simple json
2. intercept the http multiplexer to catch the flagged stream and do the
work.
1.1 create (**) a file in the apifolder /projectname/api/testapi/{
test.proto, **test_reflag.go**, test.pb.go, test.pb.gw.go}
1.2 file content:
func forwardSimpleTest(ctx context.Context, mux *runtime.ServeMux, marshaler
runtime.Marshaler, w http.ResponseWriter, req *http.Request, resp
proto.Message, opts ...func(context.Context, http.ResponseWriter,
proto.Message) error) {
w.Header().Set("json", "simplify") //flagged <<<<
runtime.ForwardResponseMessage(ctx, mux, marshaler, w, req, resp, opts...)
}
func init() {
forward_MyTest_GetSimpleTests_0 = forwardSimpleTest
//... for all calls which need to be flagged
}
2. hook the interceptor into the Responsewriter where I detect the
simplified and rewrite the JSON structure from:
{
simple:{
"key":"value",
"key":"value",
}
}
to ->
{
"key":"value",
"key":"value",
}
sad that it is not possible with the grpc gateway nor configurable with the
protobuf library...
Anyway, if somebody has the same issue this is a nice and fast workaround
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/93023180-106a-458a-bdd6-82963a06be70%40googlegroups.com.