Handle case where ZoneRecord name can be not present #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
sql
package does withNullString
.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 changingZoneRecord
would have been quite painful for consumers as each time you referencedName
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