shad-go/lectures/07-sql/alive/ping.go
2020-04-09 14:15:54 +03:00

21 lines
350 B
Go

package alive
import (
"context"
"database/sql"
"log"
_ "github.com/jackc/pgx/v4/stdlib"
)
func IsItAliveQuestionMark() {
db, err := sql.Open("pgx", "postgres://pgx_md5:secret@localhost:5432/pgx_test")
if err != nil {
log.Fatal(err)
}
defer db.Close()
if err := db.PingContext(context.Background()); err != nil {
log.Fatal(err)
}
}