Skip to content

Commit

Permalink
feat: add addr support
Browse files Browse the repository at this point in the history
  • Loading branch information
23doors committed Aug 28, 2020
1 parent ab750a8 commit f3b36c8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"context"
"fmt"
"net"
"sync"
"time"
Expand Down Expand Up @@ -42,6 +43,8 @@ type Options struct {
pg.Options

StatementTimeout int
Host string
Port string
}

// DefaultDBOptions returns
Expand All @@ -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
Expand Down

0 comments on commit f3b36c8

Please sign in to comment.