import ( "github.com/youtube/vitess/go/vt/topo" ) // get shard info for a particular keyspace and shard name shard, err := topo.GetShard(ctx, topoServer, "mykeyspace", "shard0") if err != nil { // handle error } // print out some shard info fmt.Printf("Shard: %s/%s\n", shard.Keyspace(), shard.Name()) fmt.Printf("Number of tablets: %d\n", len(shard.TabletAliases()))
import ( "github.com/youtube/vitess/go/vt/topo" ) // create a new shard for a keyspace shard := topo.NewShard("shard1", "mykeyspace") // add some tablets to the shard shard.AddTabletAlias(&topo.TabletAlias{ Cell: "us-east", Uid: 1, }) shard.AddTabletAlias(&topo.TabletAlias{ Cell: "us-west", Uid: 2, }) // save the shard info to the topology server if err := topoServer.CreateShard(ctx, "mykeyspace", shard); err != nil { // handle error }This example demonstrates how to create a new shard for a keyspace using the NewShard() function. It also shows how to add some tablets to the shard using the AddTabletAlias() function, and how to save the shard information to the topology server using the CreateShard() function.