1
0
Fork 0

added a small helper function

Dieser Commit ist enthalten in:
Sebastian Tobie 2022-11-18 14:10:59 +01:00
Ursprung b5800f09c2
Commit 8d9b870820
1 geänderte Dateien mit 9 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,7 @@ package db
import (
"context"
"errors"
"fmt"
"io/fs"
"sync"
@ -25,6 +26,14 @@ var _ ConnGet = NewMiddleware().GetConn
var _ middleware.Middleware = &Middleware{}
var _ middleware.PostSetupMiddleware = &Middleware{}
// GetConnection is an simple helper function that returns an connection to the db
func GetConnection(c *gin.Context, db string) (*pgxpool.Conn, error) {
if co, ok := c.Get(ContextKey); ok {
return co.(ConnGet)(db), nil
}
return nil, errors.New("No db.Middleware set up. ")
}
// Middleware return a handler that sets the db into the context of every request.
// uri is an url in the form dbtype:connectargs
type Middleware struct {