本文介绍云数据库 veDB MySQL 版 Go SDK 的代码示例供您参考。
使用 Go SDK 调用 veDB MySQL 接口时,默认无超时时间设置。 您可以在初始化客户端时,通过 WithHTTPClient(&http.Client{Timeout: <超时时间> * time.Second})
来指定客户端的请求超时时间,若未在该时间内完成,请求会立即终止并报超时错误。例如,您可以通过以下代码将客户端的请求超时时间设置为 10 秒。
config = volcengine.NewConfig(). WithCredentials(credentials.NewStaticCredentials(ak, sk, "")). WithRegion(region). WithEndpoint("service host"). WithHTTPClient(&http.Client{Timeout: 10 * time.Second})
以下示例中参数的详细说明请参见 CreateDBInstance。
func StringPtr(s string) *string { return &s } func Int32Ptr(i int32) *int32 { return &i } func CreateDBInstance() { InitClient() var ( resp *CreateDBInstanceOutput err error ) resp, err = VeDBMClient.CreateDBInstance(&CreateDBInstanceInput{ ChargeType: StringPtr("PostPaid"), DBEngineVersion: StringPtr("MySQL_8_0"), DBTimeZone: StringPtr("UTC +08:00"), InstanceName: StringPtr("your instance name"), LowerCaseTableNames: StringPtr("0"), NodeNumber: Int32Ptr(2), NodeSpec: StringPtr("vedb.mysql.x4.large"), ProjectName: nil, SubnetId: StringPtr("your subnet id"), SuperAccountName: StringPtr("your super account name"), SuperAccountPassword: StringPtr("your super account password"), Tags: nil, VpcId: StringPtr("your vpc id"), ZoneIds: StringPtr("cn-beijing-b"), }) if nil != err { t.Errorf("%s", err.Error()) } var respStr []byte respStr, err = json.MarshalIndent(resp, "", "\t") fmt.Printf("%s", string(respStr)) }
func DescribeDBInstanceDetail() { InitClient() var ( resp *DescribeDBInstanceDetailOutput err error ) resp, err = VeDBMClient.DescribeDBInstanceDetail(&DescribeDBInstanceDetailInput{ InstanceId: StringPtr("your instance id"), }) if nil != err { t.Errorf("%s", err.Error()) } var respStr []byte respStr, err = json.MarshalIndent(resp, "", "\t") fmt.Printf("%s", string(respStr)) }