boilerplate code

This commit is contained in:
2025-10-09 05:20:06 +02:00
parent a7c436fe4c
commit b51f00e499
17 changed files with 500 additions and 17 deletions
+24
View File
@@ -0,0 +1,24 @@
package iot
import (
"context"
"log/slog"
"github.com/jackc/pgx/v5/pgxpool"
_ "github.com/jackc/pgx/v5/stdlib"
)
func NewPGXPool(datasource string) *pgxpool.Pool {
dbPool, err := pgxpool.New(context.Background(), datasource)
if err != nil {
slog.Error("error connecting to database", "error", err, "datasource", datasource)
panic(err)
}
if err := dbPool.Ping(context.Background()); err != nil {
slog.Error("error pinging database, maybe incorrect datasource", "error", err, "datasource", datasource)
panic(err)
}
slog.Info("connected to database", "datasource", datasource)
return dbPool
}