On Fri, Jun 21, 2019 at 7:06 AM Shishir Jakati <sjak...@redhat.com> wrote: > > Say I have a struct > type MyStruct struct { > string `json:",inline"` > int `json:"omitempty"` > } > > Is there any way to utilize the JSON tags to omit the empty fields when I > call a function like > fmt.Sprintf("%#v",s) > where s is an instance of my struct?
There is no simple way. You can define a GoString method to print the struct however you like (https://golang.org/pkg/fmt/#GoStringer), but you'll have to define such a method for each type for which you want special handling. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXhERQ60odRfW3MdAp%3D0Zi%3D%2Bj8cSfE76jpUfmHSOpSLFQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.