aws-sdk-v2 中 Go 的接口重新声明:正确吗?
在 Go 的 aws-sdk-v2 库中,我们有以下接口定义:(
type Retryer interface {
GetInitialToken() (releaseToken func(error) error)
}
type RetryerV2 interface {
Retryer
GetInitialToken() (releaseToken func(error) error)
}
代码位于:https://github.com/aws/aws-sdk-go-v2/blob/main/aws/retryer.go)
这会导致编译错误:
aws/retryer.go:81: GetInitialToken redeclared (compile)
这段代码是否正确?是否可以重新声明接口中的函数? 我该如何解决这个问题?
In aws-sdk-v2 library for Go, we have the following interfaces definitions:
type Retryer interface {
GetInitialToken() (releaseToken func(error) error)
}
type RetryerV2 interface {
Retryer
GetInitialToken() (releaseToken func(error) error)
}
(the code is here: https://github.com/aws/aws-sdk-go-v2/blob/main/aws/retryer.go)
This causes compilation error:
aws/retryer.go:81: GetInitialToken redeclared (compile)
Is this code correct or not? Is it possible to redeclare function in of interfaces?
How am I supposed to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能使用的是旧版本的 Go。从 Go 1.14 开始允许重叠方法集,并且代码在 Go Playground 上编译。
引用自 Go 1.14 发布日志:
如果您发布的代码出现编译时错误,则表明您使用的是 1.14 之前的 Go。紧急更新!请注意,仅支持最后 2 个主要版本(当前为 1.17 和 1.16)。你使用像 1.13 这样的版本是一个很大的风险!
Likely you are using an old version of Go. Overlapping method sets are allowed since Go 1.14, and the code compiles on the Go Playground.
Quoting from Go 1.14 release log:
If you get a compile-time error for the code you posted, that suggests you're using a Go prior to 1.14. Urgently update! Please note that only the last 2 major versions are supported (currently 1.17 and 1.16). You using a version like 1.13 is a major risk!