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:
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