Skip to content

Breaking change for NewProviderGroup in 1.3.0? #102

@tormoder

Description

@tormoder

I'm reading a single config file where I want to override values based on priority. My initial code below worked with 1.1.0, but does not with 1.3.0. I understand that some functions have been marked deprecated in 1.3.0, but the README explicitly states that "no breaking changes will be made in the 1.x series of releases".

I see that the new NewYAML function can take multiple files with priority, but I want to read and merge a single file. Is there another way to do this in 1.3.0?

Reproduction:

config.yml file:

---
default:
  foo: Base
other:
  foo: Override

main.go:

package main

import (
        "fmt"

        "go.uber.org/config"
)

func main() {
        var conf struct {
                Foo string `yaml:"foo"`
        }

        provider, err := fromSpecificEnvs("config.yml", "default", "other")
        if err != nil {
                panic(err)
        }

        if err := provider.Get(config.Root).Populate(&conf); err != nil {
                panic(err)
        }

        fmt.Printf("Foo: %q\n", conf.Foo)
}

func fromSpecificEnvs(filepath string, envs ...string) (config.Provider, error) {
        baseProvider, err := config.NewYAMLProviderFromFiles(filepath)
        if err != nil {
                return nil, fmt.Errorf("error parsing config file: %v", err)
        }

        var subProviders []config.Provider
        for _, env := range envs {
                sp := config.NewScopedProvider(env, baseProvider)
                subProviders = append(subProviders, sp)
        }

        return config.NewProviderGroup("config", subProviders...)
}

Result using 1.1.0:
Foo: "Override"

Result using 1.3.0:
Foo: ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions