Home > Article > Backend Development > Gorm: Configuring TLS failed (sslmode invalid)
I'm trying to learn how to use gorm, but I'm facing a small, silly problem. When I try to connect to the database, the program throws me the following error:
[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)
Honestly, I don't know how to fix it and what could go wrong.
This is my code:
<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>
So where is the problem? If you know, please tell me. I am truely thankful!
The connection string should be host=localhost user=postgres password=postgres dbname=astra port=5432 sslmode=disable TimeZone=UTC
Demonstrated here in the gorm documentation
This is actually one of the formats PostgreSQL accepts for connection strings .
The above is the detailed content of Gorm: Configuring TLS failed (sslmode invalid). For more information, please follow other related articles on the PHP Chinese website!