Merge pull request #1138 from printfcoder/master
cockroach store supports URL connection string
This commit is contained in:
commit
74762edc42
@ -4,6 +4,7 @@ package cockroach
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
@ -212,9 +213,14 @@ func (s *sqlStore) configure() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
source := nodes[0]
|
source := nodes[0]
|
||||||
|
// 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, " ") {
|
if !strings.Contains(source, " ") {
|
||||||
source = fmt.Sprintf("host=%s", source)
|
source = fmt.Sprintf("host=%s", source)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create source from first node
|
// create source from first node
|
||||||
db, err := sql.Open("postgres", source)
|
db, err := sql.Open("postgres", source)
|
||||||
|
Loading…
Reference in New Issue
Block a user