I created a user by:
sudo -u postgres psql -c "CREATE USER sample;"
Then created a database:
sudo -u postgres psql -c "CREATE DATABASE practice OWNER sample;"
Now I'm trying to connect to this DB by following snippet:
dsn := url.URL{
User: url.UserPassword("sample", ""),
Scheme: "postgres",
Host: fmt.Sprintf("%s", "localhost"),
Path: "practice",
RawQuery: (&url.Values{"sslmode": []string{"disable"}}).Encode(),
}
db, err := gorm.Open(
"postgres",
dsn.String(),
)
if err != nil {
log.Fatal(err)
}
But the output is:
2020/07/07 16:43:44 pq: password authentication failed for user "sample"
How do I connect to DB with a user which has no password?