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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why not create new file when file not exists.

suutaku opened this issue · comments

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

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.
}