Skip to content

Simple way to initialize a config file #430

Open
@michaeleekk

Description

Hello. I was searching for a way to initialize the config file, but still couldn't find one.

viper.SetConfigName("config")
viper.SetConfigType("json")
viper.AddConfigPath("$HOME")

And then I tried the new SafeWriteConfig() or any of the variety merged two weeks ago, but it didn't create new file or it will overwrite the original config file no matter what. And because of the $HOME, I might need to write a function to be cross-platform. I just wish there could be a cleaner way.

Or we could add O_CREATE to this line of code ?
https://github.com/spf13/viper/blob/master/viper.go#L1254

And also is it a good idea to have SafeWriteConfig() to create a new file with the first config path and config name ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions