github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/discovery/example_test.go (about) 1 package discovery_test 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/ydb-platform/ydb-go-sdk/v3" 8 ) 9 10 func Example_discoverCluster() { 11 ctx := context.TODO() 12 db, err := ydb.Open(ctx, "grpc://localhost:2136/local") 13 if err != nil { 14 fmt.Printf("failed to connect: %v", err) 15 16 return 17 } 18 defer db.Close(ctx) // cleanup resources 19 endpoints, err := db.Discovery().Discover(ctx) 20 if err != nil { 21 fmt.Printf("discover failed: %v", err) 22 23 return 24 } 25 fmt.Printf("%s endpoints:\n", db.Name()) 26 for i, e := range endpoints { 27 fmt.Printf("%d) %s\n", i, e.String()) 28 } 29 } 30 31 func Example_whoAmI() { 32 ctx := context.TODO() 33 db, err := ydb.Open(ctx, "grpc://localhost:2136/local") 34 if err != nil { 35 fmt.Printf("failed to connect: %v", err) 36 37 return 38 } 39 defer db.Close(ctx) // cleanup resources 40 whoAmI, err := db.Discovery().WhoAmI(ctx) 41 if err != nil { 42 fmt.Printf("discover failed: %v", err) 43 44 return 45 } 46 fmt.Printf("%s whoAmI: %s\n", db.Name(), whoAmI.String()) 47 }