How to connect to Patroni using golang

120 views Asked by At

I have an application that connects to a PostgreSQL database.

package main

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/lib/pq"
)

func main() {
    connectionString := "host=<my-host> port=<my-port> user=<my-user> password=<my-password> dbname=<my-dbname> sslmode=disable"

    db, err := sql.Open("postgres", connectionString)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

//...
}

I need to connect to Patroni. How do I need to specify the connection string? Do I need to specify all servers in the cluster, or is it possible to specify only one?

0

There are 0 answers