From 101017a29c7fb3e61ceb417efe1aa2cb8bd797eb Mon Sep 17 00:00:00 2001 From: shu xian Date: Wed, 29 Jan 2020 00:47:41 +0800 Subject: [PATCH] cockroach supports URL connection string --- store/cockroach/cockroach.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index bbfadf07..d60a60f5 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -4,6 +4,7 @@ package cockroach import ( "database/sql" "fmt" + "net/url" "strings" "time" "unicode" @@ -212,8 +213,13 @@ func (s *sqlStore) configure() error { } source := nodes[0] - if !strings.Contains(source, " ") { - source = fmt.Sprintf("host=%s", source) + // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable + // if err is nil which means it would be a URL like postgre://xxxx?yy=zz + _, err := url.Parse(source) + if err != nil { + if !strings.Contains(source, " ") { + source = fmt.Sprintf("host=%s", source) + } } // create source from first node