问题内容 我正在尝试学习如何使用 gORM,但面临着一个小而愚蠢的问题。当我尝试连接到数据库时,程序向我抛出以下错误: [error] failed to initialize dat
我正在尝试学习如何使用 gORM,但面临着一个小而愚蠢的问题。当我尝试连接到数据库时,程序向我抛出以下错误:
[error] failed to initialize database, Got error cannot parse `host=localhost, user=postgres, passWord=xxxxx dbname=astra, port=5432, sslmode=disable, TimeZone=UTC`: failed to configure TLS (sslmode is invalid)
老实说,我不知道如何解决它以及可能出现什么问题。
这是我的代码:
func setupDb() {
dsn := "host=localhost, user=postgres, password=postgres, dbname=astra, port=5432, sslmode=disable, TimeZone=UTC"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
logger_config.ErrorLogger.Println("Couldn't connect to database")
}
}
那么问题出在哪里呢?如果你知道,请告诉我。我真的很感激!
连接字符串应为 host=localhost user=postgres 密码=postgres dbname=astra port=5432 sslmode=disable TimeZone=UTC
在 gorm 文档中的此处进行了演示
这实际上是格式之一postgresql 接受连接字符串。
以上就是Gorm:配置 TLS 失败(sslmode 无效)的详细内容,更多请关注编程网其它相关文章!
--结束END--
本文标题: Gorm:配置 TLS 失败(sslmode 无效)
本文链接: https://www.lsjlt.com/news/561071.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0