Skip to content
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

for V2: make more fields public #1967

Open
1 task done
drsybren opened this issue Dec 16, 2024 · 0 comments
Open
1 task done

for V2: make more fields public #1967

drsybren opened this issue Dec 16, 2024 · 0 comments
Labels
kind/enhancement New feature or request

Comments

@drsybren
Copy link

Preflight Checklist

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

Problem Description

Currently many of the Viper fields are package-private and inaccessible to the application code. This means that it's hard to get the configuration of Viper itself.

For example, when Viper cannot find the configuration file, I want to show the list of searched directories to the user. This is stored in v.configPaths, which is package-private. Of course I know that once I do v.AddConfigPath(".") it turns "." into an absolute path and stores it, and so I could do that as well when showing the paths to the user. That feels like unnecessary bookkeeping just to work around the struct field being package-private.

Another example are the name and locations fields in ConfigFileNotFoundError. If I want to present the error in a different way than produced by ConfigFileNotFoundError.Error(), I can't.

Proposed Solution

Make fields more public, especially when their access doesn't matter much. In the above case, there is no harm in making the ConfigFileNotFoundError fields public, as Viper doesn't start behaving differently when somebody modifies them. For the Viper struct itself I can imagine that this is more sensitive; in this case getter functions that return a copy of the field's value (so the original cannot be modified through a reference) would be good to have.

Alternatives Considered

No response

Additional Information

My application is something that people install & run on their own machines. It's not meant for technical folks, and thus having control over what is shown and what wording is used is quite important.

@drsybren drsybren added the kind/enhancement New feature or request label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant