-
var db *pgxpool.Pool
var ctx, cancel = context.WithTimeout(context.Background(), 15*time.Second)
func init() {
err := godotenv.Load(".env")
if err != nil {
fmt.Println("Could not load .env file")
os.Exit(1)
}
db, err = pgxpool.New(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
fmt.Println("Could not connect to database:", err)
cancel()
os.Exit(1)
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
ankurdeka
Oct 3, 2022
Replies: 1 comment 1 reply
-
Solved. There are 2 options. One is |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ankurdeka
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved.
There are 2 options. One is
Ping
and the other isAcquire
.Which one is the best option to check if the connection is successful?