-
Notifications
You must be signed in to change notification settings - Fork 153
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
feature: unmarshal with defaults and required fields #321
Comments
Try using https://github.com/go-playground/validator for validation. Use go value for defaults
|
@qianlongzt Thanks. I'm not sure that defaults approach works when doing things like generics and dynamically creating. Validator probably works for validation though it's probably overkill and one extra step and dependency. |
Hello @thnk2wn, Do you know when next release is planned ? |
@OhohLeo I'm not a maintainer of this project, was just trying to help a bit with one issue and this question. I believe the position for this project is as @qianlongzt mentioned above You could certainly try the defaults and required behavior I added using my forked version at https://github.com/teamjobot/koanf but I'm not sure if we'll maintain that yet so it may grow stale or you might run into bugs with the changes. |
It'd be great to have
required
anddefault
attribute support when unmarshalling koanf config into structs.While it might not be the primary focus of koanf, I think that unmarshalling config into structs is the primary way most want to reference the config values koanf holds.
Ensuring required configuration items are set and providing reasonable defaults when they're not is very common and we're used to the support from modules like kelseyhightower/envconfig. Without that there's a lot more tedious work to do before and after koanf loading.
I took a quick stab at merging this functionality from kelseyhightower/envconfig into a new unmarshal method in our forked repo. While it's only been quickly tested, the envconfig source is rock solid and I minimized changes for quick start. The performance could probably be improved. At any rate, it's here for reference if it's helpful for the feature intent and/or potential future implementation.
teamjobot/koanf/pull/2
The text was updated successfully, but these errors were encountered: