knadh / koanf

Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
MIT License
2.56k stars 146 forks source link

Why not create new file when file not exists. #256

Closed suutaku closed 7 months ago

suutaku commented 7 months ago

missing create feature leads developers write external code. why not just add this feature.

knadh commented 7 months ago

koanf is not a file-first library. The file provider is the same as any other provider (bytes, network etc.). It wouldn't be ideal to have file creation functions in the core, and simply creating a non-existent file provides marginal utility.

This should definitely be handled externally. Using the file provider, it should be as simple as something like:

if err := errors.Is(err, os.ErrNotExist) {
    // your business logic to create one or more files, populate them with default contents etc.
}