Skip to content

Commit

Permalink
feat(config.go): add connect_timeout to DSN parsable params
Browse files Browse the repository at this point in the history
  • Loading branch information
jessdwitch committed Apr 5, 2022
1 parent 2e4d130 commit 998b04d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions driver/pgdriver/config.go
Expand Up @@ -263,6 +263,9 @@ func parseDSN(dsn string) ([]Option, error) {
if d := q.duration("dial_timeout"); d != 0 {
opts = append(opts, WithDialTimeout(d))
}
if d := q.duration("connect_timeout"); d != 0 {
opts = append(opts, WithDialTimeout(d))
}
if d := q.duration("read_timeout"); d != 0 {
opts = append(opts, WithReadTimeout(d))
}
Expand Down
13 changes: 13 additions & 0 deletions driver/pgdriver/config_test.go
Expand Up @@ -97,6 +97,19 @@ func TestParseDSN(t *testing.T) {
WriteTimeout: 5 * time.Second,
},
},
{
dsn: "postgres://user:password@localhost:5432/testDatabase?connect_timeout=3",
cfg: &pgdriver.Config{
Network: "tcp",
Addr: "localhost:5432",
User: "user",
Password: "password",
Database: "testDatabase",
DialTimeout: 3 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 5 * time.Second,
},
},
}

for i, test := range tests {
Expand Down

0 comments on commit 998b04d

Please sign in to comment.