Map to struct with custom logics
Hi.
Thx for your library. Very helpful. I was wondering if there is any way to map a section to struct with custom types. So that every value will be transformed via a custom function.
Hi, thanks for the good idea, but unfortunately it's not supported yet. Will consider such functionality..
In a second thought, what is your definition of custom types?
Map from string to constant or function. E.g. every key in section can be "transformed" into a struct field and also validated.
Thanks, would you mind give a more realistic example so I can understand the needs better?
https://github.com/ClearcodeHQ/Go-Forward/blob/master/config.go#L162 I'd like to add some parameters that will be uints. I was thinking of some kind of function that will call a function based on key name. Validation logic and default values can be delagated to that functions which will be implemented by user.
Example.
Value of key size should be >= 0. If -1 is in file, then MapTo will silently ignore it and provide a 0. Thus I am not able to write an error message saying that value is invalid.
I see, if I understand correctly, you're asking a kind of validation feature similar to form validation, that would be a bit more complex than I would expect originally... :trollface: