You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
812 B

package common
import (
"expenses/model"
"github.com/spf13/viper"
"os"
)
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
}