pq: SSL is not enabled on the server

325 views Asked by At

I'm using SET DSN="postgres://postgres:[email protected]/food_db_development?sslmode=disable" and SET GIN_PORT=":7070" and when trying to run my main.go file i just get the error pq: SSL is not enabled on the server Does anyone know how to solve it? I saw other people with the same problem but some didn't use SQLX or had some differences that even when trying to adapt to my code didn't give any results.

My main.go code file ->

import (
    "fmt"
    "log"

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

type Config struct {
    Dsn     string `required:"true"`
    GinPort string `required:"true" split_words:"true"`
}

func LoadConfig() (*Config, error) {
    var c Config
    err := envconfig.Process("", &c)
    if err != nil {
        return nil, fmt.Errorf("failed to load config: %w", err)
    }
    return &c, nil
}

func NewPostgresDB(conf *Config) (*sqlx.DB, error) {
    db, err := sqlx.Connect("postgres", conf.Dsn)
    if err != nil {
        return nil, err
    }
    return db, nil
}

func main() {
    conf, err := LoadConfig()
    if err != nil {
        log.Fatalln(err)
    }

    log.Println("configurations: ", conf)
    db, err := NewPostgresDB(conf)
    if err != nil {
        log.Fatalln(err)
    }

    log.Println("connected to db with: ", db)
}

i'm using postgres and password as default username/password

I get the first one right but the second one not:

2023/11/09 20:07:31 configurations: &{"postgres://postgres:[email protected]/food_db_development?sslmode=disable" ":7070"} and 2023/11/09 20:07:31 pq: SSL is not enabled on the server

0

There are 0 answers