Skip to content

Commit a4e2eab

Browse files
authored
Merge pull request #1281 from ydb-platform/fix-dsn
* Allowed the use of DSN without specifying the protocol/scheme
2 parents 598174f + 5b0ee36 commit a4e2eab

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Allowed the use of DSN without specifying the protocol/scheme
12
* Removed public `query.Identifier` interface for exclude any external implementations for use with YDB
23

34
## v3.74.0

internal/dsn/dsn.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package dsn
33
import (
44
"fmt"
55
"net/url"
6+
"regexp"
67

78
"github.com/ydb-platform/ydb-go-sdk/v3/config"
89
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
910
)
1011

1112
var (
1213
insecureSchema = "grpc"
14+
secureSchema = "grpcs"
15+
reScheme = regexp.MustCompile(`^\w+://`)
1316
databaseParam = "database"
1417
)
1518

@@ -25,7 +28,13 @@ type parsedInfo struct {
2528
}
2629

2730
func Parse(dsn string) (info parsedInfo, err error) {
28-
uri, err := url.Parse(dsn)
31+
uri, err := url.ParseRequestURI(func() string {
32+
if reScheme.MatchString(dsn) {
33+
return dsn
34+
}
35+
36+
return secureSchema + "://" + dsn
37+
}())
2938
if err != nil {
3039
return info, xerrors.WithStackTrace(err)
3140
}

internal/dsn/dsn_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ func TestParseConnectionString(t *testing.T) {
104104
"",
105105
"",
106106
},
107+
{
108+
"localhost:3049/Root",
109+
true,
110+
"localhost:3049",
111+
"/Root",
112+
"",
113+
"",
114+
},
115+
{
116+
"grpc://localhost:3049/Root",
117+
false,
118+
"localhost:3049",
119+
"/Root",
120+
"",
121+
"",
122+
},
107123
} {
108124
t.Run(test.connectionString, func(t *testing.T) {
109125
info, err := Parse(test.connectionString)

0 commit comments

Comments
 (0)