shad-go/lectures/07-sql/alive/ping.go

22 lines
352 B
Go
Raw Normal View History

2020-04-09 11:15:34 +00:00
package alive
import (
"context"
"database/sql"
"log"
_ "github.com/jackc/pgx/v5/stdlib"
2020-04-09 11:15:34 +00:00
)
2021-04-08 13:41:48 +00:00
func IsItAliveQuestionMark(ctx context.Context) {
2020-04-09 11:15:34 +00:00
db, err := sql.Open("pgx", "postgres://pgx_md5:secret@localhost:5432/pgx_test")
if err != nil {
log.Fatal(err)
}
defer db.Close()
2021-04-08 13:41:48 +00:00
if err := db.PingContext(ctx); err != nil {
2020-04-09 11:15:34 +00:00
log.Fatal(err)
}
2020-04-08 19:20:23 +00:00
}