本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.BatchResponse.SetGoError方法的典型用法代碼示例。如果您正苦於以下問題:Golang BatchResponse.SetGoError方法的具體用法?Golang BatchResponse.SetGoError怎麽用?Golang BatchResponse.SetGoError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/proto.BatchResponse
的用法示例。
在下文中一共展示了BatchResponse.SetGoError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendBatch
// sendBatch unrolls a batched command and sends each constituent
// command in parallel.
func (tc *TxnCoordSender) sendBatch(batchArgs *proto.BatchRequest, batchReply *proto.BatchResponse) {
// Prepare the calls by unrolling the batch. If the batchReply is
// pre-initialized with replies, use those; otherwise create replies
// as needed.
// TODO(spencer): send calls in parallel.
batchReply.Txn = batchArgs.Txn
for i := range batchArgs.Requests {
// Initialize args header values where appropriate.
args := batchArgs.Requests[i].GetValue().(proto.Request)
method, err := proto.MethodForRequest(args)
call := &client.Call{Method: method, Args: args}
if err != nil {
batchReply.SetGoError(err)
return
}
if args.Header().User == "" {
args.Header().User = batchArgs.User
}
if args.Header().UserPriority == nil {
args.Header().UserPriority = batchArgs.UserPriority
}
args.Header().Txn = batchArgs.Txn
// Create a reply from the method type and add to batch response.
if i >= len(batchReply.Responses) {
if call.Reply, err = proto.CreateReply(method); err != nil {
batchReply.SetGoError(util.Errorf("unsupported method in batch: %s", method))
return
}
batchReply.Add(call.Reply)
} else {
call.Reply = batchReply.Responses[i].GetValue().(proto.Response)
}
tc.sendOne(call)
// Amalgamate transaction updates and propagate first error, if applicable.
if batchReply.Txn != nil {
batchReply.Txn.Update(call.Reply.Header().Txn)
}
if call.Reply.Header().Error != nil {
batchReply.Error = call.Reply.Header().Error
return
}
}
}