【深入理解TcaplusDB技術】TDR表GO SDK示例程式碼——刪除資料
阿新 • • 發佈:2022-04-18
使用工具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.