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

Add default config generation if no config found #34

Merged
3 commits merged into from Nov 21, 2019

Conversation

SmilingNavern
Copy link
Contributor

For issue #22
I am not quite sure about implementation. I've tried to found a way to ask viper if there is config file, but found none. So it's a glob checking here for a file. Maybe should move some constants like 'yml' and 'config' to variables.

@d-rk
Copy link
Collaborator

d-rk commented Nov 19, 2019

You can check whether the config file exists with something like this:

if err := viper.ReadInConfig(); err != nil {
    if _, ok := err.(viper.ConfigFileNotFoundError); ok {
        // Config file not found; ignore error if desired
    } else {
        // Config file was found but another error was produced
    }
}

@SmilingNavern
Copy link
Contributor Author

@random-dwi hi. Yeah, i thought about it, but i am not sure if this is good approach because there can be side effects of readinconfig.

What do you think i should do? Generate config in error section?

@ghost
Copy link

ghost commented Nov 20, 2019

@SmilingNavern thats why the code block checks for the specific error ConfigFileNotFoundError and only in this case the default config should be generated.

@SmilingNavern
Copy link
Contributor Author

@dwi-di understood, i will rewrite it. Thanks.

@SmilingNavern
Copy link
Contributor Author

I've rewritten it. Check please

@ghost
Copy link

ghost commented Nov 21, 2019

Looks good 👍
I added some minor changes for the error handling

@ghost ghost merged commit 4c2e748 into deviceinsight:master Nov 21, 2019
@SmilingNavern
Copy link
Contributor Author

Cool, thank you for review.

@SmilingNavern SmilingNavern deleted the default-config branch November 21, 2019 12:24
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants