hi, im facing this issue since couple of days.
this is my config.go file
package config
import (
"fmt"
"log"
"os"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
var DB *gorm.DB
func InitDB() {
var err error
dsn := fmt.Sprintf("host=%s port=%s user=%s dbname=%s sslmode=disable password=%s",
os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_USER"), os.Getenv("DB_NAME"), os.Getenv("DB_PASSWORD"))
DB, err = gorm.Open("postgres", dsn)
if err != nil {
log.Fatalf("Could not connect to the database: %v", err)
} else {
log.Fatalf("[+] access granted")
}
}
this is my docker-compose.yml file
version: '3.8'
services:
db:
image: postgres:13
container_name: xyz_game_db
environment:
POSTGRES_DB: xyz_game
POSTGRES_USER: admin
POSTGRES_PASSWORD: b0ss
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:
this is my .env file
DB_HOST=localhost
DB_PORT=5432
DB_USER=admin
DB_NAME=xyz_game
DB_PASSWORD=b0ss
PORT=8080
and this is the error o/p while trying to connect to psql container with validd credentials
PS C:\Projects\xxxxxxx> go run .\main.go
2024/06/15 19:59:10 Could not connect to the database: pq: password authentication failed for user "admin"
`exit status 1```