From 3d3208ed602cdf219cc0501a05bd9f00c6b4bd12 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 3 Feb 2021 16:27:49 +0800 Subject: [PATCH] initialize config plugins --- gorm.go | 8 ++++++++ tests/go.mod | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gorm.go b/gorm.go index 1109e8cd..6adf455a 100644 --- a/gorm.go +++ b/gorm.go @@ -106,6 +106,14 @@ func Open(dialector Dialector, config *Config) (db *DB, err error) { if config.Plugins == nil { config.Plugins = map[string]Plugin{} + } else { + for _, p := range config.Plugins { + defer func(plugin Plugin) { + if errr := plugin.Initialize(db); errr != nil { + err = errr + } + }(p) + } } if config.cacheStore == nil { diff --git a/tests/go.mod b/tests/go.mod index 67db5117..20d7206a 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -8,7 +8,7 @@ require ( github.com/lib/pq v1.6.0 github.com/stretchr/testify v1.5.1 gorm.io/driver/mysql v1.0.4 - gorm.io/driver/postgres v1.0.7 + gorm.io/driver/postgres v1.0.8 gorm.io/driver/sqlite v1.1.4 gorm.io/driver/sqlserver v1.0.6 gorm.io/gorm v1.20.12