Created
June 24, 2021 11:37
-
-
Save dipeshhkc/47fef5a2a912125c09e153f92bc3f7c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DBConnection -> return db instance | |
func DBConnection() (*gorm.DB, error) { | |
USER := "root" | |
PASS := "root" | |
HOST := "localhost" | |
PORT := "3306" | |
DBNAME := "casbin-golang" | |
newLogger := logger.New( | |
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer | |
logger.Config{ | |
SlowThreshold: time.Second, // Slow SQL threshold | |
LogLevel: logger.Info, // Log level | |
Colorful: true, // Disable color | |
}, | |
) | |
url := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", USER, PASS, HOST, PORT, DBNAME) | |
return gorm.Open(mysql.Open(url), &gorm.Config{Logger: newLogger}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment