我在尝试编译时遇到此错误:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex string
age int
)
func main() {
// connect to the cluster
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
cluster.ProtoVersion = 4
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
我添加了
行cluster.ProtoVersion = 4
在阅读了here后,但我太新了,无法理解这是我的问题,还是我在其他地方做错了什么。我是否必须等待修复此问题的gocql更新,或者我应该怎么做?
答案 0 :(得分:3)
好的,我在@ithar问题#538主题上整理了@Zariel。你必须把ProtoVersion = 4放在第一个gocql的东西上,比如:
package main
import "fmt"
import "log"
import "github.com/gocql/gocql"
var (
name, sex, age string
)
func main() {
// connect to the cluster
cluster := gocql.NewCluster("127.0.0.1")
cluster.ProtoVersion = 4
cluster.Keyspace = "dbaccess"
session, _ := cluster.CreateSession()
defer session.Close()
if err := session.Query("SELECT name, age FROM people WHERE name='doug'").Scan(&name, &age);
err != nil {
log.Fatal(err)
}
fmt.Println(name, age)
}
希望能帮助别人:)