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
806 B
30 lines
806 B
package config
|
|
|
|
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.GetInt("server.port")
|
|
config.DataSource.Host = viper.GetString("datasource.host")
|
|
config.DataSource.Port = viper.GetInt("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
|
|
}
|