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
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.
The text was updated successfully, but these errors were encountered:
Preflight Checklist
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 dov.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
andlocations
fields inConfigFileNotFoundError
. If I want to present the error in a different way than produced byConfigFileNotFoundError.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 theViper
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.
The text was updated successfully, but these errors were encountered: