Description
To provide a little more flexibility in special cases, use https://github.com/mgood/go-posix for POSIX variable expansion. Main use case is in the web component we typically have:
com.Option("listen_addr", "0.0.0.0:8000", "Address and port to listen on")
This lets us change the whole listen address via config and environment. But when using Heroku, we get a port to listen on from environment, but it's not in full listen_addr form. In order to use it, we'd have to add complex code that defeats part of the point of comlab config. As a workaround, we do something like this:
com.Option("listen_addr", "0.0.0.0:"+os.Getenv("PORT"), "Address and port to listen on")
Now the default value is to listen with the PORT
env var. But what if it's not set? Default config value should be valid if used. Sure we can set it to something else in dev.toml, but here is what it'd look like with POSIX expansion:
com.Option("listen_addr", "0.0.0.0:${PORT:-8000}", "Address and port to listen on")
Now if PORT
is set, it uses that, otherwise it uses 8000. Ideally POSIX expansion can be applied to toml config as well!