pq: SSL is not enabled on the server Postrsql golang

Issue

I want connect Postresql database with golang

Code :

  import (
    "context"
    "fmt"
    "time"

    _ "github.com/bmizerany/pq"
    "github.com/jmoiron/sqlx"
    )

  func NewPostSql()(*sql.DB,error) { 
    db, err := sql.Open("postgres", "postgres://postgres:ellez2004@localhost:5432/app?sslmode=disable")
    if err != nil { 
        return nil,err;
    }
    if err := db.Ping();err != nil {
        fmt.Println("error: ", err.Error());
    }
    return db,nil;
}

But i get error even though ssl = disable:
Error:

pq: SSL is not enabled on the server

How can I fix this??

Solution

I find problem "github.com/bmizerany/pq" package not workin.Just need
install
"github.com/lib/pq"

  import (
    "context"
    "fmt"
    "time"

    _ "github.com/lib/pq"
    "github.com/jmoiron/sqlx"
    )

  func NewPostSql()(*sql.DB,error) { 
    db, err := sql.Open("postgres", "postgres://postgres:ellez2004@localhost:5432/app?sslmode=disable")
    if err != nil { 
        return nil,err;
    }
    if err := db.Ping();err != nil {
        fmt.Println("error: ", err.Error());
    }
    return db,nil;
}

Answered By – aLLAZ

Answer Checked By – Katrina (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.