added a small helper function
Dieser Commit ist enthalten in:
Ursprung
b5800f09c2
Commit
8d9b870820
|
@ -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 {
|
||||
|
|
Laden…
In neuem Issue referenzieren