Mesmo seguindo os passos do vídeo recebo o seguinte erro
[error] failed to initialize database, got error failed to connect to `host=localhost user=root database=root`: server error (FATAL: password authentication failed for user "root" (SQLSTATE 28P01))
2022/04/19 18:19:40 Erro ao conectar com o banco de dados
panic: Erro ao conectar com o banco de dados
Abaixo segue meu codigo
version: '3'
services:
postgres:
image: "postgres"
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
- POSTGRES_DB=root
ports:
- "5432:5432"
volumes:
- ./migration/docker-database-initial.sql:/docker-entrypoint-initdb.d/docker-database-initial.sql
pgadmin-compose:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "gabriel@gmail.com"
PGADMIN_DEFAULT_PASSWORD: "123456"
ports:
- "54321:80"
depends_on:
- postgres
package database
import (
"log"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
var (
DB *gorm.DB
err error
)
func ConectaComBancoDeDados() {
stringDeConexao := "host=localhost user=root password=root dbname=root port=5432 sslmode=disable"
DB, err = gorm.Open(postgres.Open(stringDeConexao))
if err != nil {
log.Panic("Erro ao conectar com o banco de dados")
}
}