Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where ZoneRecord name can be not present #92

Merged
merged 3 commits into from
May 2, 2020

Conversation

weppos
Copy link
Member

@weppos weppos commented May 2, 2020

A ZoneRecord name can be an empty value "". This is because our API mimic the UI and it requires the consumer to specify the zone record name without the zone, in other words not the qualified name.

As a result, when the qualified name also matches the zone name (for apex), the value of name is blank:

zone: example
record: www.example.com
-> name: "www"

zone: example
record: example.com
-> name: ""

In Go, there is no way to distinguish a non-present string (null) vs a blank string. That's because the zero value of a string type is an empty string.

This is not a unique problem. Other libraries have a similar problem, such as the sql package and ORMs in general where a database string field can be null or empty.

There are 2 common approaches:

  1. Define a custom type. This is what the sql package does with NullString.
  2. Use a pointer to String. A pointer can be nil.

I tried both approaches, and I discarded the custom type as it was too much work for no real gain (the sql package also define custom interfaces for that values). So I went with a pointer. But changing ZoneRecord would have been quite painful for consumers as each time you referenced Name you would have had to remember it's a pointer.

While working on the pointer solution I realized that the pointer is really only needed for API requests. There is no case where name can be null for a real record, so consuming the API would always require a record name to be present, either blank or filled. So I decided to not change the signature of ZoneRecord but instead supply a different type of record attributes. This is actually another quite common pattern for particularly complex requests, and we also use in the Registrar where we supply special input structs to handle the payload of the registrar calls. This time I went with -Attributes and not -Input as there is a direct relationship between this struct at the zone record attributes, as well the zone record struct.

Fixes #33

@weppos weppos added bug Code defect or incorrect behavior ready-for-review Pull requests that are ready to be reviewed by other team members. labels May 2, 2020
@weppos weppos self-assigned this May 2, 2020
@weppos weppos requested a review from aeden May 2, 2020 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Code defect or incorrect behavior ready-for-review Pull requests that are ready to be reviewed by other team members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UpdateRecord requires Name field
2 participants