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 {
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 {
panic(err)
}
return with.PSQL(ctx, *c, func(pg *sql.DB) error {
go with.Every(ctx, 5*time.Second, func() {
return with.SQL(ctx, *c, func(pg *sql.DB) error {
with.Every(ctx, 5*time.Second, func() {
row := pg.QueryRowContext(ctx, `SELECT 1`)
var n int
if err := row.Err(); err != nil {
@ -35,11 +35,9 @@ func run(ctx context.Context) error {
} else if err := row.Scan(&n); err != nil {
log.Println("scan err:", err)
} else {
log.Println("ping...")
log.Println("pinged")
}
})
<-ctx.Done()
return nil
return ctx.Err()
})
}

View File

@ -25,7 +25,7 @@ func run(ctx context.Context) 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`)
var n int
if err := row.Err(); err != nil {
@ -36,8 +36,6 @@ func run(ctx context.Context) error {
log.Println("ping...")
}
})
<-ctx.Done()
return nil
return ctx.Err()
})
}