feat: return zero value in getter methods if receiver is nil#359
feat: return zero value in getter methods if receiver is nil#359
Conversation
Change-Id: If1c1c5f305cae0abda2f80b8c3e3c1ec37a3d8dc
|
Hmm. My intuition is that this seems sketchy (why should Maybe one middle ground is to do this only if the return is also a pointer. That makes BTW, part of the problem is that pointers are a bad way to do optionals in Go. (In some sense the true Go Way is to not use the pointer at all, and just get a giant empty struct for optionals, although I know that may have other drawbacks.) It might be interesting to experiment with using a generic Anyway, let me think a bit more about this before we merge. It's a simple change in the input but it seems like a bigger one in the output. |
|
I think this is a really useful feature, especially for queries with long nested fields. |
|
any update on this? |
|
Any update? |
|
I'm still a bit unsure if this is the right way, and haven't had time to figure out from scratch how I think this should work. There are some alternative ideas in my above comment and in #301; it might be helpful for someone to look into those and see if they work better (or describe why they wouldn't). |
Add nil check in go structs' getter methods, making chained function call like
a.GetB().GetC().GetD()won't panic.I have: