Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
suutaku opened this issue Nov 28, 2023 · 1 comment
Closed

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

suutaku opened this issue Nov 28, 2023 · 1 comment
Labels
question Further information is requested

Comments

@suutaku
Copy link

suutaku commented Nov 28, 2023

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

@knadh
Copy link
Owner

knadh commented Nov 28, 2023

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

@knadh knadh closed this as completed Nov 28, 2023
@knadh knadh added the question Further information is requested label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants