forked from ebhomengo/niki
1
0
Fork 0
niki/adapter/storage/init.go

23 lines
469 B
Go

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)
}
}
}