1 回答

TA貢獻1831條經驗 獲得超9個贊
InRecovery似乎被聲明為 的方法*cubicSender,而不是函數。您不能僅通過指定聲明方法的包來調用方法,您需要聲明該方法的類型的實例,然后可以通過使用實例變量的名稱限定該方法來調用該方法。
請注意,如果您想在聲明該方法的包外部使用該方法InRecovery,則需要導出定義該方法的類型(即cubicSender),或者需要以某種方式提供對未導出的實例的訪問類型,例如通過導出的變量或函數。
例如在congestion/file1.go:
package congestion
type cubicSender struct {
// ...
}
// exported function to provide access to the unexported type
func NewCubicSender() *cubicSender {
return &cubicSender{
// ...
}
}
func (c *cubicSender) InRecovery() bool {
return false
}
并在quic/file2.go:
package quic
import "path/to/congestion"
func foobar() {
c := congestion.NewCubicSender() // initialize an instance of cubicSender
if c.InRecovery() { // call InRecovery on the instance
// ...
}
}
- 1 回答
- 0 關注
- 153 瀏覽
添加回答
舉報