使用工具TdrCodeGen将service_info.xml转为go代码
func deleteExample() {
req, err := client.NewRequest(ZoneId, TableName, cmd.TcaplusApiDeleteReq)
if err != nil {
fmt.Printf("NewRequest TcaplusApiDeleteReq failed %v\n", err.Error())
return
}
fmt.Printf("deleteExample NewRequest TcaplusApiDeleteReq finish\n")
//设置结果标记位,删除成功后,返回tcaplus端的旧数据,默认为0
if err := req.SetResultFlag(3); err != nil {
fmt.Printf("SetResultFlag failed %v\n", err.Error())
return
}
fmt.Printf("deleteExample SetResultFlag finish\n")
//为request添加一条记录,(index只有在list表中支持,generic不校验)
rec, err := req.AddRecord(0)
if err != nil {
fmt.Printf("AddRecord failed %v\n", err.Error())
return
}
fmt.Printf("deleteExample AddRecord finish\n")
//申请tdr结构体并赋值key,最好调用tdr pkg的NewXXX函数,会将成员初始化为tdr定义的tdr默认值,
// 不要自己new,自己new,某些结构体未初始化,存在panic的风险
data := service_info.NewService_Info()
data.Gameid = "dev"
data.Envdata = "oa"
data.Name = "com"
//将tdr的数据设置到请求的记录中
if err := rec.SetData(data); err != nil {
fmt.Printf("SetData failed %v\n", err.Error())
return
}
if resp, err := client.Do(req, time.Duration(2*time.Second)); err != nil {
fmt.Printf("recv err %s\n", err.Error())
return
} else {
tcapluserr := resp.GetResult()
if tcapluserr != 0 {
fmt.Printf("response ret errCode: %d, errMsg: %s", tcapluserr, terror.GetErrMsg(tcapluserr))
return
}
//获取同步请求Seq
fmt.Printf("request Seq %d\n", req.GetSeq())
//获取回应消息的序列号
fmt.Printf("respond seq: %d \n", resp.GetSeq())
//response中带有获取的旧记录
fmt.Printf("deleteExample response success record count %d\n", resp.GetRecordCount())
for i := 0; i < resp.GetRecordCount(); i++ {
record, err := resp.FetchRecord()
if err != nil {
fmt.Printf("FetchRecord failed %s\n", err.Error())
return
}
oldData := service_info.NewService_Info()
if err := record.GetData(oldData); err != nil {
fmt.Printf("record.GetData failed %s\n", err.Error())
return
}
fmt.Printf("deleteExample response record data %+v, route: %s",
oldData, string(oldData.Routeinfo[0:oldData.Routeinfo_Len]))
fmt.Printf("deleteExample request record data %+v, route: %s",
data, string(data.Routeinfo[0:data.Routeinfo_Len]))
}
}
}
TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)