clay icon indicating copy to clipboard operation
clay copied to clipboard

How to implement emit default to response or have flag option

Open zengzhengrong opened this issue 4 years ago • 2 comments

https://stackoverflow.com/questions/34716238/golang-protobuf-remove-omitempty-tag-from-generated-json-tags The zero vaule of field be omited, I remove omitempty flag in struct, but it do not work in reponse

zengzhengrong avatar Jun 19 '20 10:06 zengzhengrong

You can override global marshaler using httpruntime:

https://github.com/utrack/clay/blob/master/transport/httpruntime/mjson.go#L13

httpruntime.OverrideMarshaler("application/json",httpruntime.MarshalerPbJSON{
	Marshaler:       &runtime.JSONPb{EmitDefaults: true},
	Unmarshaler:     &runtime.JSONPb{},
	GogoMarshaler:   &gogojsonpb.Marshaler{EmitDefaults:true},
	GogoUnmarshaler: &gogojsonpb.Unmarshaler{},
})

utrack avatar Jun 19 '20 11:06 utrack

I will prepare https://github.com/utrack/clay/issues/84 After closing that issue you'll be able to configure this param

wish-master avatar Jun 19 '20 11:06 wish-master