github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/coordination/example_test.go (about) 1 package coordination_test 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/ydb-platform/ydb-go-sdk/v3" 8 "github.com/ydb-platform/ydb-go-sdk/v3/coordination" 9 ) 10 11 //nolint:errcheck 12 func Example() { 13 ctx := context.TODO() 14 db, err := ydb.Open(ctx, "grpc://localhost:2136/local") 15 if err != nil { 16 fmt.Printf("failed to connect: %v", err) 17 18 return 19 } 20 defer db.Close(ctx) // cleanup resources 21 // create node 22 err = db.Coordination().CreateNode(ctx, "/local/test", coordination.NodeConfig{ 23 Path: "", 24 SelfCheckPeriodMillis: 1000, 25 SessionGracePeriodMillis: 1000, 26 ReadConsistencyMode: coordination.ConsistencyModeRelaxed, 27 AttachConsistencyMode: coordination.ConsistencyModeRelaxed, 28 RatelimiterCountersMode: coordination.RatelimiterCountersModeDetailed, 29 }) 30 if err != nil { 31 fmt.Printf("failed to create node: %v", err) 32 33 return 34 } 35 defer db.Coordination().DropNode(ctx, "/local/test") 36 e, c, err := db.Coordination().DescribeNode(ctx, "/local/test") 37 if err != nil { 38 fmt.Printf("failed to describe node: %v", err) 39 40 return 41 } 42 fmt.Printf("node description: %+v\nnode config: %+v\n", e, c) 43 }