Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Section inheritance #8

Open
satyrius opened this issue Nov 1, 2013 · 0 comments
Open

Section inheritance #8

satyrius opened this issue Nov 1, 2013 · 0 comments

Comments

@satyrius
Copy link

satyrius commented Nov 1, 2013

Values can contain format strings which refer to other values in the same section, or values in a special default section. But it would be great to make section inheritance. For example all key/value pairs can be available for getting from another section (not only for string formatting). Or the inheritance syntax can be provided explicity

[default]
host=example.com
scheme=http
version=v1.0
service-path=/api/%(version)s/
service-url=%(scheme)s://%(host)s%(service-path)s

[dev : default]
host=dev.service.com

[prod : default]
host=service.com

[test : default]

The sample usage

func TestClientServiceUrl(t *testing.T) {
    cfg, _ := goconfig.ReadConfigFile("/etc/my/config.cfg")

    expectations := map[string]string{
        "dev":  "http://dev.service.com/api/v1.0/",
        "test": "http://example.com/api/v1.0/",
        "prod": "http://service.com/api/v1.0/",
    }
    for section, url := range expectations {
        serviceUrl, _ := cfg.GetString(section, "service-url")
        if serviceUrl != url {
            t.Errorf("Expected service url is '%v', got '%v'", url, serviceUrl)
        }
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant