From 0e993da370c96dba4ab5d84eafe00ce5b7d5a4d5 Mon Sep 17 00:00:00 2001 From: Horacio Duran Date: Sat, 4 Aug 2018 20:08:47 -0300 Subject: [PATCH] Add conn max lifetime --- db/connection/connection.go | 1 + db/postgrespq/connection.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/db/connection/connection.go b/db/connection/connection.go index 3d6c2f4..30a54dd 100644 --- a/db/connection/connection.go +++ b/db/connection/connection.go @@ -33,6 +33,7 @@ type Information struct { User string Password string QueryExecTimeout *time.Duration //optionally set the maximum time a query can take to execute + ConnMaxLifetime *time.Duration TLSConfig *tls.Config // config for TLS connection -- nil disables TLS UseFallbackTLS bool // Try FallbackTLSConfig if connecting with TLSConfig fails. Used for preferring TLS, but allowing unencrypted, or vice-versa diff --git a/db/postgrespq/connection.go b/db/postgrespq/connection.go index a4f61be..abaf35f 100644 --- a/db/postgrespq/connection.go +++ b/db/postgrespq/connection.go @@ -109,6 +109,9 @@ func (c *Connector) Open(ci *connection.Information) (connection.DB, error) { if err != nil { return nil, errors.Wrap(err, "connecting to postgres database") } + if ci.ConnMaxLifetime != nil { + conn.SetConnMaxLifetime(*ci.ConnMaxLifetime) + } return &DB{ conn: conn, logger: conLogger,