Skip to content

Commit 27a45b8

Browse files
authored
Merge pull request #571 from ydb-platform/ref-exanples
refactoring of exaamples
2 parents 1bc78be + 3e60924 commit 27a45b8

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

connection_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,16 @@ package ydb_test
66
import (
77
"context"
88
"errors"
9-
"fmt"
109
"testing"
1110
"time"
1211

1312
"github.com/stretchr/testify/require"
1413
grpcCodes "google.golang.org/grpc/codes"
1514

1615
"github.com/ydb-platform/ydb-go-sdk/v3"
17-
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
1816
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
1917
)
2018

21-
func ExampleOpen() {
22-
ctx := context.TODO()
23-
db, err := ydb.Open(ctx, "grpc://localhost:2135/local")
24-
if err != nil {
25-
fmt.Printf("connection failed: %v", err)
26-
}
27-
defer db.Close(ctx) // cleanup resources
28-
fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name())
29-
}
30-
31-
func ExampleOpen_advanced() {
32-
ctx := context.TODO()
33-
db, err := ydb.Open(
34-
ctx,
35-
"grpc://localhost:2135/local",
36-
ydb.WithAnonymousCredentials(),
37-
ydb.WithBalancer(
38-
balancers.PreferLocationsWithFallback(
39-
balancers.RandomChoice(), "a", "b",
40-
),
41-
),
42-
ydb.WithSessionPoolSizeLimit(100),
43-
)
44-
if err != nil {
45-
fmt.Printf("connection failed: %v", err)
46-
}
47-
defer db.Close(ctx) // cleanup resources
48-
fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name())
49-
}
50-
5119
func TestZeroDialTimeout(t *testing.T) {
5220
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
5321
defer cancel()

example_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99

1010
"github.com/ydb-platform/ydb-go-sdk/v3"
11+
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
1112
"github.com/ydb-platform/ydb-go-sdk/v3/retry"
1213
"github.com/ydb-platform/ydb-go-sdk/v3/table"
1314
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/named"
@@ -173,3 +174,33 @@ func Example_discovery() {
173174
fmt.Printf("%d) %s\n", i, e.String())
174175
}
175176
}
177+
178+
func ExampleOpen() {
179+
ctx := context.TODO()
180+
db, err := ydb.Open(ctx, "grpc://localhost:2135/local")
181+
if err != nil {
182+
fmt.Printf("connection failed: %v", err)
183+
}
184+
defer db.Close(ctx) // cleanup resources
185+
fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name())
186+
}
187+
188+
func ExampleOpen_advanced() {
189+
ctx := context.TODO()
190+
db, err := ydb.Open(
191+
ctx,
192+
"grpc://localhost:2135/local",
193+
ydb.WithAnonymousCredentials(),
194+
ydb.WithBalancer(
195+
balancers.PreferLocationsWithFallback(
196+
balancers.RandomChoice(), "a", "b",
197+
),
198+
),
199+
ydb.WithSessionPoolSizeLimit(100),
200+
)
201+
if err != nil {
202+
fmt.Printf("connection failed: %v", err)
203+
}
204+
defer db.Close(ctx) // cleanup resources
205+
fmt.Printf("connected to %s, database '%s'", db.Endpoint(), db.Name())
206+
}

0 commit comments

Comments
 (0)