package conf import ( "github.com/spf13/viper" "github.com/aceberg/WatchYourLAN/internal/check" "github.com/aceberg/WatchYourLAN/internal/models" ) // Get - get app config func Get(path string) (config models.Conf) { viper.SetDefault("HOST", "0.0.0.0") viper.SetDefault("PORT", "8840") viper.SetDefault("THEME", "solar") viper.SetDefault("COLOR", "dark") viper.SetDefault("NODEPATH", "") viper.SetConfigFile(path) viper.SetConfigType("yaml") err := viper.ReadInConfig() check.IfError(err) viper.AutomaticEnv() // Get ENVIRONMENT variables config.Host = viper.Get("HOST").(string) config.Port = viper.Get("PORT").(string) config.Theme = viper.Get("THEME").(string) config.Color = viper.Get("COLOR").(string) config.NodePath = viper.Get("NODEPATH").(string) return config } // Write - write config to file func Write(config models.Conf) { viper.SetConfigFile(config.ConfPath) viper.SetConfigType("yaml") viper.Set("HOST", config.Host) viper.Set("PORT", config.Port) viper.Set("THEME", config.Theme) viper.Set("COLOR", config.Color) viper.Set("NODEPATH", config.NodePath) err := viper.WriteConfig() check.IfError(err) }