package common import ( "expenses/model" "github.com/spf13/viper" "os" ) var Config model.Config func ConfigInit() (model.Config, error) { var config model.Config workDir, _ := os.Getwd() viper.SetConfigName("app") viper.SetConfigType("yml") viper.AddConfigPath(workDir + "/config") err := viper.ReadInConfig() if err != nil { return config, err } config.Server.Port = viper.GetString("server.port") config.DataSource.Host = viper.GetString("datasource.host") config.DataSource.Port = viper.GetString("datasource.port") config.DataSource.Database = viper.GetString("datasource.database") config.DataSource.Username = viper.GetString("datasource.username") config.DataSource.Password = viper.GetString("datasource.password") config.DataSource.Charset = viper.GetString("datasource.charset") return config, nil } func GetConfig() model.Config { return Config }