Closed Ale1ster closed 3 years ago
This is bug, thanks for bringing it up. Per the documentation, both should be supported until I rev the major version. If there is a scenario where the new tag (badgerhold:"key"
) works but the old one (badgerholdKey
) doesn't, that's a bug.
Thanks,
So, the supported keys are badgerholdKey
and badgerhold:"key"
. But in that case, why are all tags in the package test structs badgerholdKey:"Key"
?
If it is an issue with reflect
's field tag retrieval, it seems Lookup
is supported for both formats (both badgerholdKey:"anything-here"
and badgerholdKey
).
If so, I think the documentation could be a little clearer.
I agree there are missing tests for the future deprecated key tag format, otherwise this issue would've been caught.
What additional info do you think should be added to the documentation?
I think that the current documentation (as included in your previous post) is complete enough, but it should note the proper way to use the tag as badgerholdKey:""
, which seems to be the tag conventional format.
Otherwise there will be inconsistencies with reflect.StructTag.Lookup
and reflect.StructTag.Get
, since the tag is looked up using Lookup
in some places and using the StructTag
value itself in others.
Yeah the solution isn't to force everyone to use the proper tag format, because I documented it wrong, and wrote it wrong originally. If I don't want to break backwards compatibility with existing software using this library, I have to support the wrong way of doing it everywhere, or I need to rev the major version of the library.
Wouldn't supporting both the unmapped tag and the conventional tag format for badgerholdKey
, as well as the badgerhold:"key"
format across all uses of key tags be a solution?
Attached is a proposed patch that seems to do that, and from what I understand shouldn't break backwards compatibility.
Changing the tag check to substring check on the tag string representation, should ensure that it is permissive enough to accept both badgerholdKey
and badgerholdKey:""
.
As referenced in the README, the key field tag for a struct can be either
badgerholdKey
orbadgerhold:"key"
, but in the package tests the tag `badgerholdKey:"Key" is used.Is that an issue of outdated documentation?
When a
uint64
struct field is tagged as a struct key, it behaves differently (badgerhold.Store.Get
andbadgerhold.Store.Find
) depending on which tag is used.What is the correct way to declare a key field?
Sorry for the long test, but I am not well-versed with reflection in Go.