英文:
How to get around "function ends without a return statement" when running `go get` in golang
问题
你可以尝试使用以下命令来安装这个Cassandra的Golang驱动程序:
go get github.com/gocql/gocql
这个驱动程序的官方仓库已经迁移到了github.com/gocql/gocql
。你可以使用上述命令来获取最新版本的驱动程序并安装它。
英文:
I am trying to install this Cassandra driver for golang: https://github.com/tux21b/gocql
When I execute go get https://github.com/tux21b/gocql
I get
root@backend:/vagrant# go get tux21b.org/v1/gocql
# tux21b.org/v1/gocql
/usr/lib/go/src/pkg/tux21b.org/v1/gocql/conn.go:280: function ends without a return statement
/usr/lib/go/src/pkg/tux21b.org/v1/gocql/conn.go:359: function ends without a return statement
/usr/lib/go/src/pkg/tux21b.org/v1/gocql/conn.go:407: function ends without a return statement
/usr/lib/go/src/pkg/tux21b.org/v1/gocql/marshal.go:1000: function ends without a return statement
How can I manage the package to be installed?
答案1
得分: 7
遇到这个特定的编译错误时,首先要确保你已经从Go的1.0版本升级到1.1版本或更高版本。
原因是Go编译器在检测不返回预期返回值的函数时变得更加智能。例如,像这样的函数:
function check(n int) bool {
if n > 10 {
return true
} else {
return false
}
}
在Go 1.0中会导致编译错误,但Go 1.1可以正确检测到这个函数总是返回一个值,是没有问题的。
英文:
The first thing to do when encountered with this particular compile error is to make sure you have upgraded from version 1.0 of Go to version 1.1 or newer.
The reason is that Go compiler have become smarter in detecting functions that don’t return their expected return values. For example, a function like this:
function check(n int) bool {
if n > 10 {
return true
} else {
return false
}
}
would lead to a compile error with Go 1.0, but Go 1.1 can correctly detect that this function always return a value and is OK.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论