From f3b36c86a85c3a67d71c3c43908658f584ce2650 Mon Sep 17 00:00:00 2001 From: Robert Kopaczewski Date: Fri, 28 Aug 2020 18:51:41 +0200 Subject: [PATCH] feat: add addr support --- database/database.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/database/database.go b/database/database.go index be17a71..f866805 100644 --- a/database/database.go +++ b/database/database.go @@ -2,6 +2,7 @@ package database import ( "context" + "fmt" "net" "sync" "time" @@ -42,6 +43,8 @@ type Options struct { pg.Options StatementTimeout int + Host string + Port string } // DefaultDBOptions returns @@ -59,6 +62,17 @@ func DefaultDBOptions() *Options { func (o *Options) PGOptions() *pg.Options { opts := o.Options + + if o.Host != "" { + port := o.Port + + if port == "" { + port = "5432" + } + + opts.Addr = fmt.Sprintf("%s:%s", o.Host, port) + } + if opts.Dialer == nil { opts.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { var conn net.Conn