predefined errors for loading a file
mayeter opened this issue · comments
Hello, I am switching to koanf from viper for some issues, everything looks good. Its simple and works well. I just couldn't find a way to verify if a file doesn't exist or just has a typo.
I would like to check multiple files in predefined locations on server and follow an order of precedence, at this point I should know if file "/etc/my_service/x" exists or not so that I can give decide to look for file "/var/lib/my_service/x". Is it possible?
you initialize koanf, use os.Stat to check if file A exists and then use Koanf.Load with a file provider and like a dotenv parser (or yaml or json, etc) to load your config file B.
You basically manually implement the logic when and what to load into koanf's internal map[string]any data structure.
Here is an example of custom logic, not exactly your use case but it might show how it's done:
https://github.com/jxsl13/archive-diff/blob/main/config/koanf.go