utrack / clay

Proto-first minimal server platform for gRPС+REST+Swagger APIs
MIT License
289 stars 39 forks source link

How to implement emit default to response or have flag option #92

Open zengzhengrong opened 4 years ago

zengzhengrong commented 4 years ago

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

utrack commented 4 years ago

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{},
})
wish-master commented 4 years ago

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