为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
有只小跳蛙 2022-09-19 17:30:59
死机:运行时错误:内存地址无效或无指针取消引用当我添加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                }            }
查看完整描述

1 回答

?
jeck猫

TA贡献1909条经验 获得超7个赞

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


查看完整回答
反对 回复 2022-09-19
  • 1 回答
  • 0 关注
  • 51 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信