Open dccmmtop opened 2 years ago
import ( "fmt" "github.com/spf13/viper" "os" "path/filepath" ) type Config struct { DesDir string SourceFiles []string } func loadConfig()(con Config){ home := os.Getenv("HOME") viper.SetConfigFile(filepath.Join(home,"config","syncFile.yml")) viper.SetConfigType("yml") err := viper.ReadInConfig() checkErr(err) err = viper.Unmarshal(&con) checkErr(err) fmt.Printf("config: %v\n", con) return con } func checkErr(err error){ if err != nil { panic(err) } }