Thanks & some thoughts (add param, fallback to env, fallback to default)
the-hotmann opened this issue · comments
First of all: thanks! I completely switched to your package as I like it most! I mainly use EnvOrDefault
since I always want a fallback default for all possible environment variables.
Sometimes I still am missing the possibillity to handle parameters with this.
I think it would be awesome, if this tool could handle:
- params
- env-vars
So the new function would be called: ParamEnvOrDefault
and would look something like this:
Example for String:
val := getenv.ParamEnvOrDefault("value", "VALUE", "testString")
fmt.Println(val)
A short form could be (with just two values passed to the function):
val := getenv.ParamEnvOrDefault("VALUE", "testString")
fmt.Println(val)
As "VALUE" (written uppercase) shall be taken as ENV-VAR.
and "value" (written lowercase) shall be taken as parameter.
so getenv.ParamEnvOrDefault("any_VALUE", "testString")
can take any value and will automatically transform it to uppercase (for ENV-VAR) and to lowercase (for parameter).
So if I here some examples on how it should work:
Nothing is set (default/fallback will be taken)
$ go run main.go
testString
Just ENV is set - (ENV will be taken)
$ export VALUE=testStringENV
$ go run main.go
testStringENV
ENV & parameter is set - (param will be taken)
$ export VALUE=testStringEnv
$ go run main.go --value=testStringPARAM
testStringPARAM
That would make it very usable outside a docker container (while using docker containers probably everyone uses ENV-VARs only).
But if ou have your compiled main.go as app
and store it on your device, you still want to be able to pass parameters to it.
Would be super awesome if you could manage to implement that. This also would not include any breaking changes, as existing code would not be touched.
P.S.: I am open for discussion
Hi @MartinHotmann!
Thanks for your feedback and your suggestion! I get where you're coming from, but I'm trying to keep this project focused, and the feature you're suggesting falls a bit outside of what I have in mind.
This isn't to say your idea isn't good – it just doesn't quite fit into what I'm aiming for with this particular library. It might make a great standalone project or add-on, though!
Keep the ideas coming, and thanks again for your interest and input.
Best regards,
Oleg