dongmu1914
2019-09-14 12:54
浏览 197
已采纳

无法将函数中的变量从另一个包调用到另一个非主函数golang

I know there are lots of other questions like this but they are all about calling a function from a main.go, which is not my case. In file1.go I have a function like this:

func (c *cubicSender) InRecovery() bool {
    return c.largestAckedPacketNumber <= c.largestSentAtLastCutback && c.largestAckedPacketNumber != 0
}

func (c *cubicSender) InSlowStart() bool {
    return c.GetCongestionWindow() < c.GetSlowStartThreshold()
}

I want to assign these functions into variables IR and ISS in file2.go. So when a function is called:

if IR == true {
            fmt.Println(pathID, pth.sentPacketHandler.GetCongestionWindow(), pth.sentPacketHandler.GetBytesInFlight(), pth.rttStats.SmoothedRTT(), time.Now().UnixNano(), "SS")
} else if ISS == true {
            fmt.Println(pathID, pth.sentPacketHandler.GetCongestionWindow(), pth.sentPacketHandler.GetBytesInFlight(), pth.rttStats.SmoothedRTT(), time.Now().UnixNano(), "IR")
}

How can I do that?

*Edit: I have imported the package, which has file1.go in file2.go.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题