-2

恐慌:运行时错误:无效的内存地址或零指针取消引用

当我添加

statusCOD, err := c.route.FindStatusCODByOrigin(ctx, req.Origin)
            if err != nil {
                if err != sql.ErrNoRows {
                    ddlogger.Log(ctx, span, "Find status cod destination and cod origin", err)
                    errChan <- err
                    return
                }
            }

            if statusCOD != nil {
                IsCODOrigin = statusCOD.IsCODOrigin
                IsCODDestination = statusCOD.IsCODDestination
            }

在这个函数中

for i, v := range detailShipments {
        var dtPackage repo.PackageBaseModel

        go func(idx int, vShipment repo.ShipmentDetailBaseModel, dataShipmentNew repo.ShipmentCODCreateModel) {
            defer wg1.Done()

            randomID := commonString.RandomWithCustomCharList(c.config.ShipmentCODIDRandom, c.config.ShipmentIDCharlist)
            shipmentID := fmt.Sprintf("%s%s", prefix, randomID)
            dataShipmentNew.ShipmentBaseModel.ShipmentID = strings.ToUpper(shipmentID)
            dataShipmentNew.ShipmentDetailBaseModel = vShipment
            var commodityName string

            sCategory, err := c.shipmentCategoryRepo.FindOneShipmentCategoryByID(ctx, vShipment.ShipmentCategoryID.Int64)

            if err != err && err != sql.ErrNoRows {
                ddlogger.Log(ctx, span, "shipmentService-CreateShipmentCOD "+shipmentID, " Failed shipmentCategoryRepo.FindOneShipmentCategoryByID", err)
            } else {
                if sCategory != nil {
                    commodityName = sCategory.CommodityName.String
                }
            }

            req := &repo.TariffRequestModelV2{
                Origin:      form.DetailSender.Origin,
                Destination: vShipment.Destination,
                Weight:      vShipment.GrossWeight / 1000,
                Commodity:   commodityName,
                GoodsValue:  int64(vShipment.GoodValues.Float64),
                IsInsurance: vShipment.IsInsurance.Bool,
                Product:     vShipment.ProductType,
                Width:       vShipment.DimensionWidth.Float64,
                Height:      vShipment.DimensionHeight.Float64,
                Length:      vShipment.DimensionLength.Float64,
                IsCOD:       true,
                CODValue:    vShipment.CODValue.Float64,
            }

            tariff, err := c.coreSystemRepo.CheckTariffV3(ctx, req)
            if err != nil {
                ddlogger.Log(ctx, span, "[shipmentService-CreateShipmentCOD [coreSystemRepo.CheckTariffV3]]", err)
                errChan <- err
                return
            }
            statusCOD, err := c.route.FindStatusCODByOrigin(ctx, req.Origin)
            if err != nil {
                if err != sql.ErrNoRows {
                    ddlogger.Log(ctx, span, "Find status cod destination and cod origin", err)
                    errChan <- err
                    return
                }
            }

            if statusCOD != nil {
                IsCODOrigin = statusCOD.IsCODOrigin
                IsCODDestination = statusCOD.IsCODDestination
            }
             ................
}
    wg1.Wait()
    close(shipmentChan)
    close(errChan)
    close(amountChan)
4

1 回答 1

0

看起来您刚刚创建了指针,并且它没有指向任何内存空间,您可以检查新代码中的所有变量以找到它。例如 ctx

于 2021-08-10T07:09:02.793 回答