I'm new to GoLang and I`ve an issue with connecting my Go webserver with Postgres Database. Can someone tell me what I'm doing wrong here? All these credentials are correct btw. User exists, Password is correct, DB exists and belongs to the user.
package app
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
func connectDB(){
db, err := gorm.Open("postgres", "host=localhost port=5432 user=power_user dbname=local_db password=power_user")
if err != nil {
log.Fatal("DB Connection failed")
}
}
If you're sure about psql server is running, try to modify pg_hba.conf
, locates at /etc/postgresql/${version}/main/pg_hba.conf
usually:
# TYPE DATABASE USER ADDRESS METHOD
local all all trust