Skip to content

v0.21 β†’ v0.22: Containable.ConfigFiles() added

What changed

The config.Containable interface gains one method:

// ConfigFiles returns the ordered list of config files that contributed to this
// container's live configuration, in merge order (lowest to highest precedence
// among file sources). Returns an empty slice for reader/embedded containers
// that were not loaded from any file. The slice is a copy.
ConfigFiles() []string

*config.Container already implements it (backed by the existing internal configFiles slice, copied under the container lock). Sub-containers report the root container's files, since the file set is a property of the loaded configuration as a whole.

The method exists because the merge precedence chain can read several files, but Viper's ConfigFileUsed() returns only the last one. config path (new in this release) needs the full ordered list to show users every file that contributed to their effective config.

Impact

  • Most consumers (none): code that obtains a Containable from config.Load*/config.New* or props.Config and embeds/uses *Container needs no change β€” the method is already implemented on the concrete type.
  • Direct Containable implementers (soft break): any type that implements config.Containable itself (rather than embedding *Container) must add a ConfigFiles() []string method or it will no longer satisfy the interface. This is rare. Per the pre-1.0 API-stability policy this ships as a minor bump, not a major.
  • Mocks: mocks/pkg/config/Containable.go is regenerated to include the new method. Tools that vendor or regenerate their own mocks should run their mock generator.

How to migrate

If you have a hand-written Containable implementation, add:

func (m *myContainer) ConfigFiles() []string {
    // return the ordered file list backing this implementation,
    // or nil/[]string{} if it is not file-backed.
    return nil
}

Embedders of *config.Container and consumers of the interface need do nothing.