package initialize import ( "fmt" "gopkg.in/yaml.v3" "gorm.io/driver/mysql" "gorm.io/gorm" "jypay/config" "os" ) const FilePath = "./config.yaml" func InitConfig() *config.Config { content, err := os.ReadFile(FilePath) if err != nil { fmt.Printf("err: %v\n", err) panic(err) } var conf config.Config if err := yaml.Unmarshal(content, &conf); err != nil { fmt.Printf("err: %v\n", err) panic(err) } return &conf } func InitDB(conf *config.Config) *gorm.DB { db, err := gorm.Open(mysql.Open(conf.Database.GetDsn()), &gorm.Config{}) if err != nil { panic(err) } return db }