You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Will result in error, as config.Field could not be found while parsing the environment, even though it had been set way before that.
Therefore, I propose respecting the pre-existing struct values when checking for required and notEmpty.
This should not be a breaking change, as it basically introduces a new feature that wasn't possible before. The upside of this, as shown in the example, is that you can compute a default, instead of just passing literals, but even just passing literals makes the whole thing much more readable than having everything in some magic string.
We would be willing to be the ones to implement this, but we wanted to check whether you'd want to accept this change at all. Alternatively, we could also make this an option, such as RespectPreExistingStructValues or something like that.
The change would be something along the lines of this:
We just realised, that for certain types, we can't know whether the value has been explicitly specified. For example, for int 0 we couldn't tell if it was set explicitly or not. This means, that both required and notEmpty can't really be checked in these cases.
This would mean, that we could only avoid throwin an error, if the value was non empty. The solution of the library user would be, to "simply" not make such fields required or nonEmpty if those fields allow zero values, which are also the default.
For pointer types however, we could be a bit more concrete. If it is a pointer to a zero value, we can say it fullfils required, but not notEmpty. The same goes for arrays, slices and maps. Should we still proceed with this? It is a little inconsistent, but the type system doesn't hold more information, necessary for a more consistent solution.
So what we'd do instead, is to keep the current checks as they are, but extend them with edge cases where the errors are omitted, in case we can be sure a value has been set / set to someting non empty.
We would also clarify this behaviour in the readme and maybe provide an example or two. Either way, this still wouldn't change behaviour for people that still do things the v9 way.
Hey
Currently, doing something like this:
Will result in error, as config.Field could not be found while parsing the environment, even though it had been set way before that.
Therefore, I propose respecting the pre-existing struct values when checking for
required
andnotEmpty
.This should not be a breaking change, as it basically introduces a new feature that wasn't possible before. The upside of this, as shown in the example, is that you can compute a default, instead of just passing literals, but even just passing literals makes the whole thing much more readable than having everything in some magic string.
We would be willing to be the ones to implement this, but we wanted to check whether you'd want to accept this change at all. Alternatively, we could also make this an option, such as
RespectPreExistingStructValues
or something like that.The change would be something along the lines of this:
The text was updated successfully, but these errors were encountered: