niki/adapter/storage/init.go

23 lines
469 B
Go
Raw Normal View History

2023-12-16 06:09:50 +00:00
package storage
import (
"fmt"
)
var DB DBMS
func Init() {
var eErr error
//I. Define a data source name (DSN)
dsn := "niki_user:NIKI_user@123@tcp(127.0.0.1:3306)/niki?charset=utf8mb4&parseTime=True&loc=Local"
//II. Try to connect to dsn address
DB, eErr = GormConnect(dsn)
//III. If gorm connect successfully then try to migrate database
if eErr == nil {
err := GormAutoMigrate(*DB.db)
if err != nil {
fmt.Errorf("some error .... %#v", err)
}
}
}