我正试图运行一个空中飞行的例子:
package main
import (
"github.com/aerospike/aerospike-client-go"
"fmt"
)
func panicOnError(err error) {
if err != nil {
panic(err)
}
}
func main() {
// define a client to connect to
client, err := NewClient("127.0.0.1", 3000)
panicOnError(err)
key, err := NewKey("test", "aerospike", "key")
panicOnError(err)
// define some bins with data
bins := BinMap{
"bin1": 42,
"bin2": "An elephant is a mouse with an operating system",
"bin3": []interface{}{"Go", 2009},
}
// write the bins
err = client.Put(nil, key, bins)
panicOnError(err)
// read it back!
rec, err := client.Get(nil, key)
panicOnError(err)
fmt.Printf("%#v\n", *rec)
// delete the key, and check if key exists
existed, err := client.Delete(nil, key)
panicOnError(err)
fmt.Printf("Record existed before delete? %v\n", existed)
}
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
Unresolved reference NewClient...
and many more...
Run Code Online (Sandbox Code Playgroud)
我运行命令:
go get github.com/aerospike/aerospike-client-go
Run Code Online (Sandbox Code Playgroud)
它已将软件包下载到磁盘上.
你能帮我吗?
你可以在项目aerospike/aerospike-client-go测试中看到example_listiter_int_test.go:
导入项目:
as "github.com/aerospike/aerospike-client-go"
Run Code Online (Sandbox Code Playgroud)使用具有正确前缀的NewClient:
var v as.Value = as.NewValue(myListInt([]int{1, 2, 3}))
Run Code Online (Sandbox Code Playgroud)所以不要忘记加前缀NewClient.
在你的情况下:
import (
as "github.com/aerospike/aerospike-client-go"
"fmt"
)
Run Code Online (Sandbox Code Playgroud)
和:
client, err := as.NewClient("127.0.0.1", 3000)
Run Code Online (Sandbox Code Playgroud)
as是包名称的别名,因为,如" 在Go中从另一个包调用函数 "中所述:
您通过其导入路径导入包,并通过包名称引用其所有导出的符号(以大写字母开头的符号),
由于NewClient是在client.go的package aerospike,另一种是:
client, err := aerospike.NewClient("127.0.0.1", 3000)
Run Code Online (Sandbox Code Playgroud)