adminClient,err:=bigtable.NewAdminClient(ctx,project,instance)iferr!=nil{log.Fatalf("Unable to create a table admin client. %v",err)}tables,err:=adminClient.Tables(ctx)iferr!=nil{log.Fatalf("Unable to fetch table list. %v",err)}if!sliceContains(tables,tableName){iferr:=adminClient.CreateTable(ctx,tableName);err!=nil{log.Fatalf("Unable to create table: %v. %v",tableName,err)}}tblInfo,err:=adminClient.TableInfo(ctx,tableName)iferr!=nil{log.Fatalf("Unable to read info for table: %v. %v",tableName,err)}if!sliceContains(tblInfo.Families,familyName){iferr:=adminClient.CreateColumnFamily(ctx,tableName,familyName);err!=nil{log.Fatalf("Unable to create column family: %v. %v",familyName,err)}}adminClient.Close()
然后,代码示例会创建一个 Bigtable 客户端,该客户端将用于所有后续的读取和写入操作:
client,err=bigtable.NewClient(ctx,project,instance)iferr!=nil{log.Fatalf("Unable to create data operations client. %v",err)}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-06。"],[[["This is a Go-based App Engine application that uses Bigtable to track the number of visits from each user's Google account."],["The application can be run locally in a Docker container or in the cloud within App Engine's flexible environment."],["Upon launch, the code creates a Bigtable administrative client to manage the `user-visit-counter` table and its `emails` column family, creating them if they don't exist."],["The application uses a Bigtable client for reads and writes, and it includes an HTTP handler that prompts users to log in and then increments their visit count in Bigtable."],["The app does not provide any access control for the user data and should be shutdown after testing."]]],[]]