package config

import (
	"log"

	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
)

func InitConfig(configName, configType, configPath string) {
	viper.Reset()
	viper.SetConfigName(configName)
	viper.SetConfigType(configType)
	viper.AddConfigPath(configPath)
	viper.WatchConfig()
	viper.OnConfigChange(func(in fsnotify.Event) {
		log.Println("Config update ", in.Name)
	})

	err := viper.ReadInConfig()
	if err != nil {
		log.Fatal("InitConfig failed ", err)
	}
}

func Get(key string) interface{} {
	return viper.Get(key)
}
func GetString(key string) string {
	return viper.GetString(key)
}
func GetStringSclice(key string) []string {
	return viper.GetStringSlice(key)
}
