loopd: instruct REST proxy to print default values

pull/140/head
Oliver Gugger 4 years ago
parent 3e25bc3174
commit e070494565
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -97,11 +97,22 @@ func daemon(config *config, lisCfg *listenerCfg) error {
} }
defer grpcListener.Close() 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 // We'll also create and start an accompanying proxy to serve clients
// through REST. // through REST.
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
mux := proxy.NewServeMux() mux := proxy.NewServeMux(customMarshalerOption)
proxyOpts := []grpc.DialOption{grpc.WithInsecure()} proxyOpts := []grpc.DialOption{grpc.WithInsecure()}
err = looprpc.RegisterSwapClientHandlerFromEndpoint( err = looprpc.RegisterSwapClientHandlerFromEndpoint(
ctx, mux, config.RPCListen, proxyOpts, ctx, mux, config.RPCListen, proxyOpts,

Loading…
Cancel
Save