gliderlabs / gliderlabs/comlab

default config value environment interpolation

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
16
Forks
4
PR merge metrics
No merged PRs in 30d

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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.