我遇到了恐慌:运行时错误:Golang中的内存地址无效或nil指针取消引用

死机:运行时错误:内存地址无效或无指针取消引用


当我添加


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

                }

            }

有只小跳蛙
浏览 52回答 1
1回答

jeck猫

看起来您刚刚创建了指针,并且它不指向任何内存空间,您可以检查新代码中的所有变量以找到它。例如
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go