From 3c54b657b24b368cde001e334c502065d9d3668d Mon Sep 17 00:00:00 2001 From: zodial Date: Wed, 20 Nov 2024 16:28:30 +0800 Subject: [PATCH] =?UTF-8?q?update:=20postgresql=E5=85=BC=E5=AE=B9ssl?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../providers/postgresql/postgresql_provider.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bootstrap/providers/postgresql/postgresql_provider.go b/bootstrap/providers/postgresql/postgresql_provider.go index 15eb70a..17940f3 100644 --- a/bootstrap/providers/postgresql/postgresql_provider.go +++ b/bootstrap/providers/postgresql/postgresql_provider.go @@ -9,6 +9,7 @@ import ( "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" + "strings" ) // PostgresqlProvider @Bean("postgresql") @@ -51,11 +52,16 @@ func (p *PostgresqlProvider) Init() { gConf.Logger.LogMode(logger.LogLevel(logrus.DebugLevel)) } - dsn := postgres.Open(fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=disable TimeZone=%v", host, username, password, dbname, port, timezone)) + dsnStr := fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=require TimeZone=%v", host, username, password, dbname, port, timezone) + dsn := postgres.Open(dsnStr) db, err := gorm.Open(dsn, gConf) if err != nil { - logrus.Error("postgresql 链接错误", err) - panic(err) + dsn = postgres.Open(strings.Replace(dsnStr, "require", "disable", 1)) + db, err = gorm.Open(dsn, gConf) + if err != nil { + logrus.Error("postgresql 链接错误", err) + panic(err) + } } p.dbs[name.(string)] = db }