Init Commit: After finish database connection.

This commit is contained in:
2025-07-19 14:13:43 +08:00
commit 56c625ee6b
14 changed files with 375 additions and 0 deletions

42
config/config.go Normal file
View 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()
}