edit template

main
Bel LaPointe 2025-12-11 10:13:02 -07:00
parent 3f69a2d5d5
commit 558d2f7f9d
2 changed files with 7 additions and 11 deletions

View File

@ -21,13 +21,13 @@ func main() {
func run(ctx context.Context) error { func run(ctx context.Context) error {
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
c := fs.String("c", "postgresql://pulsegres:pulsegres@localhost:15432", "conn string") c := fs.String("c", "sqlite://", "conn string")
if err := fs.Parse(os.Args[1:]); err != nil { if err := fs.Parse(os.Args[1:]); err != nil {
panic(err) panic(err)
} }
return with.PSQL(ctx, *c, func(pg *sql.DB) error { return with.SQL(ctx, *c, func(pg *sql.DB) error {
go with.Every(ctx, 5*time.Second, func() { with.Every(ctx, 5*time.Second, func() {
row := pg.QueryRowContext(ctx, `SELECT 1`) row := pg.QueryRowContext(ctx, `SELECT 1`)
var n int var n int
if err := row.Err(); err != nil { if err := row.Err(); err != nil {
@ -35,11 +35,9 @@ func run(ctx context.Context) error {
} else if err := row.Scan(&n); err != nil { } else if err := row.Scan(&n); err != nil {
log.Println("scan err:", err) log.Println("scan err:", err)
} else { } else {
log.Println("ping...") log.Println("pinged")
} }
}) })
return ctx.Err()
<-ctx.Done()
return nil
}) })
} }

View File

@ -25,7 +25,7 @@ func run(ctx context.Context) error {
} }
return with.SQL(ctx, *c, func(db *sql.DB) error { return with.SQL(ctx, *c, func(db *sql.DB) error {
go with.Every(ctx, 5*time.Second, func() { with.Every(ctx, 5*time.Second, func() {
row := db.QueryRowContext(ctx, `SELECT 1`) row := db.QueryRowContext(ctx, `SELECT 1`)
var n int var n int
if err := row.Err(); err != nil { if err := row.Err(); err != nil {
@ -36,8 +36,6 @@ func run(ctx context.Context) error {
log.Println("ping...") log.Println("ping...")
} }
}) })
return ctx.Err()
<-ctx.Done()
return nil
}) })
} }