Init Commit: After finish database connection.
This commit is contained in:
42
config/config.go
Normal file
42
config/config.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user