Skip to content

Add viper.IsNonDefaultSet to check if a value is set by config, not default value #1814

@haoming29

Description

@haoming29

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

Currently, viper.IsSet returns true if the key has a default value. However, it would be useful to know if a value is set by the user via config/env/etc.

Proposed Solution

Have a new method to check if a key is set by config/env other than the default value. It seems that viper keeps the default values of keys in v.defaults map:

viper/viper.go

Line 1400 in d539b7a

val = v.searchMap(v.defaults, path)
so it's doable to implement this feature.

Alternatives Considered

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions