我正在嘗試查詢一個測試鍵空間,如:package mainimport "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 文件夾中的方法但找不到它,或者導入內容的語法錯誤?
1 回答

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
我認為您的問題是您在此處將 gocql var 聲明為字符串:
var (
gocql string
)
您應該刪除它,它應該可以解決該特定問題。
此外,您的導入聲明:
import _ "github.com/gocql/gocql"
不應包含下劃線 ( _),因為您明確使用 gocql 而不僅僅是為了它的副作用而導入。
- 1 回答
- 0 關注
- 183 瀏覽
添加回答
舉報
0/150
提交
取消