
我正在尝试学习如何使用 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)
老实说,我不知道如何解决它以及可能出现什么问题。
这是我的代码:
<code>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")
}
}
</code>那么问题出在哪里呢?如果你知道,请告诉我。我真的很感激!
连接字符串应为 host=localhost user=postgres 密码=postgres dbname=astra port=5432 sslmode=disable TimeZone=UTC
在 gorm 文档中的此处进行了演示
这实际上是格式之一PostgreSQL 接受连接字符串。
以上就是Gorm:配置 TLS 失败(sslmode 无效)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号