Added better error handling
Dieser Commit ist enthalten in:
Ursprung
2326ceb32e
Commit
1d647c7d00
|
@ -29,7 +29,10 @@ 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
|
||||
if cg, ok := co.(ConnGet); ok {
|
||||
return cg(db), nil
|
||||
}
|
||||
return nil, fmt.Errorf("Failed to convert the method. %T != ConnGet", co)
|
||||
}
|
||||
return nil, errors.New("No db.Middleware set up. ")
|
||||
}
|
||||
|
@ -101,7 +104,7 @@ func (m *Middleware) GetConn(name string) *pgxpool.Conn {
|
|||
|
||||
// Gin is the Entrypoint for Gin.
|
||||
func (m *Middleware) Gin(c *gin.Context) {
|
||||
c.Set(ContextKey, m.GetConn)
|
||||
c.Set(ContextKey, ConnGet(m.GetConn))
|
||||
}
|
||||
|
||||
// Setup adds the connections from the configfile into the middleware
|
||||
|
|
Laden…
In neuem Issue referenzieren