Skip to content

Commit 5e45912

Browse files
committed
add describe topic
1 parent 44b5d0f commit 5e45912

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

topic/example_test.go

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import (
1212
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
1313
)
1414

15-
func Example_create_topic() {
15+
func Example_createTopic() {
1616
ctx := context.TODO()
17-
db, err := connectDB(ctx)
17+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
18+
if connectionString == "" {
19+
connectionString = "grpc://localhost:2136/local"
20+
}
21+
db, err := ydb.Open(ctx, connectionString)
1822
if err != nil {
1923
log.Fatalf("failed connect: %v", err)
2024
return
@@ -35,9 +39,13 @@ func Example_create_topic() {
3539
}
3640
}
3741

38-
func Example_alter_topic() {
42+
func Example_alterTopic() {
3943
ctx := context.TODO()
40-
db, err := connectDB(ctx)
44+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
45+
if connectionString == "" {
46+
connectionString = "grpc://localhost:2136/local"
47+
}
48+
db, err := ydb.Open(ctx, connectionString)
4149
if err != nil {
4250
log.Fatalf("failed connect: %v", err)
4351
return
@@ -56,9 +64,34 @@ func Example_alter_topic() {
5664
}
5765
}
5866

59-
func Example_drop_topic() {
67+
func Example_describeTopic() {
6068
ctx := context.TODO()
61-
db, err := connectDB(ctx)
69+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
70+
if connectionString == "" {
71+
connectionString = "grpc://localhost:2136/local"
72+
}
73+
db, err := ydb.Open(ctx, connectionString)
74+
if err != nil {
75+
log.Fatalf("failed connect: %v", err)
76+
return
77+
}
78+
defer db.Close(ctx) // cleanup resources
79+
80+
descResult, err := db.Topic().Describe(ctx, "topic-path")
81+
if err != nil {
82+
log.Fatalf("failed drop topic: %v", err)
83+
return
84+
}
85+
fmt.Printf("describe: %#v\n", descResult)
86+
}
87+
88+
func Example_dropTopic() {
89+
ctx := context.TODO()
90+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
91+
if connectionString == "" {
92+
connectionString = "grpc://localhost:2136/local"
93+
}
94+
db, err := ydb.Open(ctx, connectionString)
6295
if err != nil {
6396
log.Fatalf("failed connect: %v", err)
6497
return
@@ -72,9 +105,13 @@ func Example_drop_topic() {
72105
}
73106
}
74107

75-
func Example_read_message() {
108+
func Example_readMessage() {
76109
ctx := context.TODO()
77-
db, err := connectDB(ctx)
110+
connectionString := os.Getenv("YDB_CONNECTION_STRING")
111+
if connectionString == "" {
112+
connectionString = "grpc://localhost:2136/local"
113+
}
114+
db, err := ydb.Open(ctx, connectionString)
78115
if err != nil {
79116
log.Fatalf("failed connect: %v", err)
80117
return
@@ -102,11 +139,3 @@ func Example_read_message() {
102139
fmt.Println(string(content))
103140
}
104141
}
105-
106-
func connectDB(ctx context.Context) (ydb.Connection, error) {
107-
connectionString := os.Getenv("YDB_CONNECTION_STRING")
108-
if connectionString == "" {
109-
connectionString = "grpc://localhost:2135/local"
110-
}
111-
return ydb.Open(ctx, connectionString)
112-
}

0 commit comments

Comments
 (0)