I'm just using pointers now, this approach seems to work fine for my purpose: https://go.dev/play/p/lMwZisTayt3
Steffen Wentzel schrieb am Samstag, 26. Februar 2022 um 11:00:49 UTC+1: > Dear community, > > how can we XML marshal a struct field depending on the value of another > struct field in the same struct? > > Playground Example: https://go.dev/play/p/vfRB-GfzZ54 > > My approaches so far: > > - Use a custom type for the Feature field and implement xml.Marshaler. > However MarshalXML has no access to other fields, so I might need some > sort > of "closure", not sure how to put that together > - Implement xml.Marshaler for the entire struct - due to the number of > fields included in the real struct (> 100), I guess this would be a lot of > work.. > - Use separate types for each "ItemType" - this replicates a lot of > work because most struct fields are needed for both ItemType values > > > I hope someone with more experience can give me some hints or tips. > > Thank you and all the best, > Steffen > -- 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/b04b333e-a902-4774-a7a0-1940353a648cn%40googlegroups.com.