From 3410ad912236950ee1df9c7557c23777e0bd77a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Oct 2018 17:19:52 +0100 Subject: [PATCH] Add host query parameter to support unix sockets Currently there is no way to specify unix sockets in the connection url. This patch adds a `host` query parameter that allows to set the path. --- conn.go | 5 +++++ conn_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/conn.go b/conn.go index a8b61547..22fa3de4 100644 --- a/conn.go +++ b/conn.go @@ -782,6 +782,11 @@ func ParseURI(uri string) (ConnConfig, error) { continue } + if k == "host" { + cp.Host = v[0] + continue + } + cp.RuntimeParams[k] = v[0] } if cp.Password == "" { diff --git a/conn_test.go b/conn_test.go index 763efd11..c0419d90 100644 --- a/conn_test.go +++ b/conn_test.go @@ -458,6 +458,19 @@ func TestParseURI(t *testing.T) { }, }, }, + { + url: "postgres:///foo?host=/tmp", + connParams: pgx.ConnConfig{ + Host: "/tmp", + Database: "foo", + TLSConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + UseFallbackTLS: true, + FallbackTLSConfig: nil, + RuntimeParams: map[string]string{}, + }, + }, } for i, tt := range tests {