Comments (13)
I can totally see the usefulness. For the time being you could definitely implement this on individual fields with a custom decoder that goes and reads the file itself.
That's been my answer to a lot of feature requests, and it's a nice way to keep envconfig
itself simple -- get opinionated on the basics, and also offer a total swiss army knife. Not sure where I stand on this though, seems useful enough that first-class support makes a sort of sense too.
from envconfig.
@teepark what about an option to provide a custom lookup function or interface? It would require some minor refactoring but people could add their own custom lookup and their own custom tags, thus giving a path to customization without having to expand the scope of this repository (or maintain a fork).
p := envconfig.New()
p = envconfig.NewPrefix("FOO_") // alternate constructor
p.Lookup = func(info VarInfo) (bool, string) { /* custom logic */ }
p.Process(spec)
Note that this would not replace or remove the existing global Process
and MustProcess
functions. These global functions would invoke NewPrefix
under the hood. This is similar to how the json package has global functions, that create encoders and decoders under the hood.
from envconfig.
Just wanted to say that this would be great!
from envconfig.
I think @teepark had answered @bradrydzewski 's question.
This issue should be closed.
from envconfig.
the answer also indicates first class support could make sense. If that is the case I would be happy to send a pull request. If not, I completely understand and this issue can be closed.
from envconfig.
@bradrydzewski
Could you try with https://github.com/kelseyhightower/envconfig#custom-decoders ?
from envconfig.
I understand this can be achieved with custom decoders. I am interested in contributing a patch to support this natively. If this is out-of-scope for the project I completely understand and this can be closed. We need this feature and we use this library for 100+ repositories ,and are therefore comfortable maintaining our own fork if needed.
from envconfig.
I can feel your enthusiasm from the comment.
Could you talk about the advantage and disadvantage if you want to send the PR.
I expect I can hear about the feature brings value except for the technical layer, how about it effect this community? If it encounters bottleneck, how does it maintain and optimize in the future?
from envconfig.
Personally, I am sorry to talk about that.
We are engineers. We should understand a lib of responsibility.
If there is a core goal or focused solution goal, we think we can define the behavior and functionality to complete the target.
If it does thing is not on the track, we should stop that and introspect, maybe it's over-engineering.
I am not sure, it's correct or wrong. But at least, we have Github this platform provides discussion chance to make engineers communicate.
Please use here and express your idea. Before taking actions, I want to know how you think.
from envconfig.
Just to chime in, I am very much in favour of this, it would be fantastic! Docker swarm is not going to be dying anytime soon it seems, so this request will probably only be coming more and more ;)
from envconfig.
This is a great idea and I'd love to see @bradrydzewski's PR get merged.
from envconfig.
I think it's important to limit the scope of this library. If we don't stop at files, then soon people will want us to load data from secrets managers and key/value stores. Custom lookup functions make sense to me and I think it's the right path forward.
from envconfig.
I'll ask a very basic question: How would the scenario described in the original issue (i.e. picking either POSTGRES_PASSWORD_FILE
or POSTGRES_PASSWORD
) look like when implemented using a custom decoder function?
Maybe I am missing something, but from what I understand a custom decoder would only allow me to check whether the provided env value might be a file and then try to read it (which means I'd have to define POSTGRES_PASSWORD=/run/secrets/postgrespassword
). But it wouldn't let me retrieve the configuration value from either the one or the other source? The custom decoder doesn't even receive the key that has been used for looking up the passed value.
from envconfig.
Related Issues (20)
- Feature Request: multiple names for fields HOT 4
- Support for map[string]interface{} HOT 1
- environment variable does not precede default envconfig value in struct HOT 1
- Add support for getting a FlagSet from envconfig HOT 1
- Possible to populate fields discretely for a slice of structs? HOT 4
- Syntax for map of structs or other maps HOT 1
- envconfig does not reach nested structs HOT 3
- Feature Request: Ability to get list of ENV variables HOT 2
- Var not found after being exported HOT 1
- Maps configuration with value including colon character HOT 3
- Incorrectly reading long strings HOT 1
- time.Duration support for days notation
- Support a second API func to control environments source
- Set `split_words` as a global option HOT 4
- support optional trim
- Error message from required field should include prefix if specified. HOT 1
- Required by default
- Support for conditional requirement of variables
- Is this project still maintained? HOT 5
- Feature Request: Make usage available in machine processable format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envconfig.