0

I use viper to load runtime environment specific property files (located under ./configs/*.conf). I am looking to see how I can embed these files in the binary.

Following snippet that loads the files

viper.AddConfigPath("./configs")
viper.SetConfigName("app_dev.conf")
viper.ReadInConfig()

I have tried using the following embed directive

//go:embed configs/*.conf
var resources embed.FS

However getting an error that it cannot load the property files. It works, as expected, if I add the config folder in the same location as the binary.

Rocky
  • 365
  • 1
  • 5
  • 15

1 Answers1

0

I realized that I can use io.reader to load Viper config

data, _ := _configFile.ReadFile("configs/app_dev.conf")
err = viper.ReadConfig(strings.NewReader(string(data)))
Rocky
  • 365
  • 1
  • 5
  • 15