https://github.com/spf13/viper/blob/5870123c5f385c8d88b7087d15d2e1b7fa67a7fa/README.md?plain=1#L144

That line of the readme is a bit confusing. It took navigating the git blame history to find https://github.com/spf13/viper/commit/9cd571279d195d6a02b5103f0301d8310dd4338d and reviewing the commit in context for me to understand that it is saying a file named ~/.foo can be loaded as YAML when viper.SetConfigType("yaml") is used.

I was looking for a way to support the following file path possibilities:

  • /etc/foo/config.yaml
  • $HOME/.foo
  • $HOME/.foo.yaml
  • ./.foo
  • ./.foo.yaml

It's still not clear to me if I can support that list.

Comment From: github-actions[bot]

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

Comment From: sagikazarmark

@jsumners I don't think it's possible with the current implementation. I agree it's confusing, not very well explained and evolved in the wrong way over time.

I opened #1795 with a proposal for a better file searching API.

Here is how it would work in your case:

finder := locafero.Finder{
    Paths: []string{".", "$HOME", "/etc/foo"},
    Names: []string{".foo", ".foo.yaml", "config.yaml"},
    Type:  locafero.FileTypeFile,
}

v := viper.New(viper.WithFinder(finder))

The above is still not perfect though since it would allow results like $HOME/config.yaml.

I opened sagikazarmark/locafero#26 to address that. Considering that proposal, here is how it would roughly look like:

finder := locafero.AggregateFinders(
    locafero.Finder{
        Paths: []string{".", "$HOME"},
        Names: []string{".foo", ".foo.yaml"},
        Type:  locafero.FileTypeFile,
    },
    locafero.Finder{
        Paths: []string{"/etc/foo"},
        Names: []string{"config.yaml"},
        Type:  locafero.FileTypeFile,
    },
)

v := viper.New(viper.WithFinder(finder))

You could potentially play with supporting multiple file types if you wanted to.

What do you think? Would this suffice your needs? (Your feedback would be very helpful as I just started to work on this solution, so I'm looking to validate this new API)

Comment From: github-actions[bot]

Issues with no activity for 30 days are marked stale and subject to being closed.