Skip to main content

Command Palette

Search for a command to run...

When you can't find a conf file by your Golang code

Published
•1 min read•View as Markdown
S

I'm to shy to write smth about me For now

That happens because Go search for a config file at the root of your project. This solution works if the file is in some other directory.

workingdir, err := os.Getwd()
if err != nil {
    log.Fatalf("can't get pwd: %s", err)
}

and then

viper.AddConfigPath(workingdir + "/")
viper.SetConfigName("app")
viper.SetConfigType("env")

or just

viper.SetConfigFile(workingdir + "/app.env")