From e070494565ac6f3569ea9959a979faeac385606b Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 31 Jan 2020 13:57:24 +0100 Subject: [PATCH] loopd: instruct REST proxy to print default values --- loopd/daemon.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/loopd/daemon.go b/loopd/daemon.go index 533698d..8313382 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -97,11 +97,22 @@ func daemon(config *config, lisCfg *listenerCfg) error { } defer grpcListener.Close() + // The default JSON marshaler of the REST proxy only sets OrigName to + // true, which instructs it to use the same field names as specified in + // the proto file and not switch to camel case. What we also want is + // that the marshaler prints all values, even if they are falsey. + customMarshalerOption := proxy.WithMarshalerOption( + proxy.MIMEWildcard, &proxy.JSONPb{ + OrigName: true, + EmitDefaults: true, + }, + ) + // We'll also create and start an accompanying proxy to serve clients // through REST. ctx, cancel := context.WithCancel(context.Background()) defer cancel() - mux := proxy.NewServeMux() + mux := proxy.NewServeMux(customMarshalerOption) proxyOpts := []grpc.DialOption{grpc.WithInsecure()} err = looprpc.RegisterSwapClientHandlerFromEndpoint( ctx, mux, config.RPCListen, proxyOpts,