How to get around "function ends without a return statement" when running `go get` in golang

huangapple go评论81阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2013年9月15日 20:16:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/18812268.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定