GoLand 开发报错:reflect.Value.Interface: cannot return value obtained from unexported field or method,解决方法及代码优化
// batchGetOrderInfoList 批量请求云rpc接口,控制并发数N func batchGetOrderInfoList(ctx context.Context, uin string, orders []*pb.OrderListDetails, returnOrderList []*pb.OrderListDetails) ([]string, error) { failedTsIds := make([]string, 0) tasks := make([]func() error, 0)
for i := 0; i < len(orders); i++ {
order := orders[i]
// 创建任务
task, failedTsId := createTask(ctx, uin, order)
tasks = append(tasks, task)
if failedTsId != "" {
failedTsIds = append(failedTsIds, failedTsId)
}
}
return failedTsIds, util.GoAndWait(10, tasks...)
}
func createTask(ctx context.Context, uin string, order *pb.OrderListDetails) (func() error, string) { log.InfoContextf(ctx, '查询按消费明细开票信息-子任务, 订单号=%v', order.GetSubOrderNo()) failedTsId := order.GetSubOrderNo() task := func() error { // 请求云接口按照订单号获取订单的未开票金额、已开票金额 GetInvoiceOrderListRsp, err := cloudBilling.GetInvoiceOrderList(ctx, uin, 1, 1, order.GetSubOrderNo()) if err != nil { log.ErrorContextf(ctx, 'createTask qcloud.invoice.GetOrderInfoList.err, sub_order_no=%+v', order.GetSubOrderNo()) return err } log.InfoContextf(ctx, 'GetInvoiceOrderList.Rsp=%+v', GetInvoiceOrderListRsp) log.InfoContextf(ctx, 'GetInvoiceOrderList.Rsp=%v', GetInvoiceOrderListRsp) if GetInvoiceOrderListRsp == nil { return errors.New('云接口数据异常,GetInvoiceOrderListRsp is nil') } if GetInvoiceOrderListRsp.ReturnCode != 0 { log.ErrorContextf(ctx, 'GetInvoiceOrderList.Rsp.err=%v', GetInvoiceOrderListRsp.ReturnMessage) return errors.New(GetInvoiceOrderListRsp.ReturnMessage) } log.InfoContextf(ctx, 'GetInvoiceOrderListRsp.Data.Detail') detailList := GetInvoiceOrderListRsp.Data.Detail if len(detailList) == 0 { return errors.New('云接口数据异常,订单数量为0') } if len(detailList) > 0 { returnOrder := &pb.OrderListDetails{} proto.Merge(returnOrder, order) log.InfoContextf(ctx, 'GetInvoiceOrderList len(detailList)') // 追加订单字段 returnOrder.UnInvoiceAmt = proto.Float64(detailList[0].UnInvoiceAmount) returnOrder.InvoiceAmt = proto.Float64(detailList[0].InvoicedAmount) returnOrderList = append(returnOrderList, returnOrder) //无失败返回时设置为空 failedTsId = "" } log.InfoContextf(ctx, 'order=%+v', order) log.InfoContextf(ctx, 'order=%v', order) return nil } log.InfoContextf(ctx, 'task=%+v, failedTsId=%v', task, failedTsId) return task, failedTsId }
原文地址: https://www.cveoy.top/t/topic/oBIW 著作权归作者所有。请勿转载和采集!