46 lines
675 B
Go
46 lines
675 B
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
App struct {
|
|
Name string
|
|
Port string
|
|
}
|
|
Database struct {
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Name string
|
|
Charset string
|
|
}
|
|
Bcrypt struct {
|
|
Cost int
|
|
}
|
|
}
|
|
|
|
var AppConfig *Config
|
|
|
|
func InitConfig() {
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("yml")
|
|
viper.AddConfigPath("./config")
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
log.Fatalf("Error reading config file, %v", err)
|
|
}
|
|
|
|
AppConfig = &Config{}
|
|
|
|
if err := viper.Unmarshal(AppConfig); err != nil {
|
|
log.Fatalf("Unable to decode into struct, %v", err)
|
|
}
|
|
|
|
initDB()
|
|
}
|