我试图查询一个测试密钥空间,例如:
package main
import "fmt"
import _ "github.com/gocql/gocql"
var (
gocql string
)
func main() {
// connect to the cluster
cluster := gocql.NewCluster("127.0.0.1")
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)
}但我犯了一个错误,比如:
12: gocql.NewCluster undefined (type string has no field or method NewCluster)这是否意味着它试图指向gocql/gocql文件夹中的方法,但却找不到它,还是语法错误?
发布于 2016-01-14 01:11:44
我认为您的问题是在这里将gocql var声明为字符串:
var (
gocql string
)你应该删除它,它应该解决这个特定的问题。
此外,您的导入声明:
import _ "github.com/gocql/gocql"不应该包含下划线(_),因为您显式地使用gocql,而不仅仅是导入它的副作用。
https://stackoverflow.com/questions/34779824
复制相似问题