Skip to content

Add nil-safe getters for optional Go fields - #41

Closed
THEjacob1000 wants to merge 1 commit into
feat/go-codegen-optional-scalarsfrom
feat/go-codegen-optional-getters
Closed

THEjacob1000 wants to merge 1 commit into
feat/go-codegen-optional-scalarsfrom
feat/go-codegen-optional-getters

Conversation

@THEjacob1000

@THEjacob1000 THEjacob1000 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Internal change only

[LOKE-XXXX]

Generated Go clients now have nil-safe getters for optional fields that #39 turns into pointers. Inspired by Go protobuf scalar getters: pointers track presence; getters return values or defaults. Callers that don't need to distinguish absence from a zero value can use Get<Field>(), including on a nil receiver, instead of repeating nil checks.

Getters are also generated for object definitions reached through refs. Names that collide with existing fields or getters gain an underscore suffix, preserving the existing field names and keeping the generated client compilable.

This stacks on #39. Consumers can adopt getters where zero-value fallback is appropriate and keep checking the pointer where presence matters; the JSON format stays unchanged.

Related PRs

Screenshots / Videos

I have:

  • Run and tested the code and provided clear evidence of this above
  • Self reviewed the code and removed extraneous comments, debug logging, checked code style
  • Listed any dependant PRs required for this change
  • Added tests where practical and possible
  • Documented a way to roll this change back if it is more than a code revert

all the above must be ticked

@THEjacob1000
THEjacob1000 requested a review from MrDwarf7 October 7, 2026 01:53
@THEjacob1000
THEjacob1000 force-pushed the feat/go-codegen-optional-getters branch 2 times, most recently from d7f59e1 to 60191b4 Compare October 7, 2026 01:55
@THEjacob1000
THEjacob1000 force-pushed the feat/go-codegen-optional-getters branch from 60191b4 to bc1bb74 Compare October 7, 2026 01:58

@smithamax smithamax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why

@smithamax

Copy link
Copy Markdown
Member

I don't see how this solves anything related to the parent PR

@THEjacob1000

Copy link
Copy Markdown
Contributor Author

it doesn't fix anything, the pointers do. getters are just qol so callers that don't care about presence can do f.GetName() instead of nil-checking every optional field, same as proto's GetX(). anything that needs to know if a field was sent still checks f.Name != nil

@THEjacob1000
THEjacob1000 removed the request for review from MrDwarf7 October 7, 2026 20:41
@THEjacob1000
THEjacob1000 deleted the feat/go-codegen-optional-getters branch October 7, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants