Skip to content

Commit e070494

Browse files
committed
loopd: instruct REST proxy to print default values
1 parent 3e25bc3 commit e070494

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

loopd/daemon.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,22 @@ func daemon(config *config, lisCfg *listenerCfg) error {
9797
}
9898
defer grpcListener.Close()
9999

100+
// The default JSON marshaler of the REST proxy only sets OrigName to
101+
// true, which instructs it to use the same field names as specified in
102+
// the proto file and not switch to camel case. What we also want is
103+
// that the marshaler prints all values, even if they are falsey.
104+
customMarshalerOption := proxy.WithMarshalerOption(
105+
proxy.MIMEWildcard, &proxy.JSONPb{
106+
OrigName: true,
107+
EmitDefaults: true,
108+
},
109+
)
110+
100111
// We'll also create and start an accompanying proxy to serve clients
101112
// through REST.
102113
ctx, cancel := context.WithCancel(context.Background())
103114
defer cancel()
104-
mux := proxy.NewServeMux()
115+
mux := proxy.NewServeMux(customMarshalerOption)
105116
proxyOpts := []grpc.DialOption{grpc.WithInsecure()}
106117
err = looprpc.RegisterSwapClientHandlerFromEndpoint(
107118
ctx, mux, config.RPCListen, proxyOpts,

0 commit comments

Comments
 (0)