Reputation: 201
I'm trying to run an aerospike go example:
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)
}
But I get an error:
Unresolved reference NewClient...
and many more...
I've run the command:
go get github.com/aerospike/aerospike-client-go
and it has downloaded the package on the disk.
Can you help?
Upvotes: 3
Views: 281
Reputation: 1323593
You can see in the project aerospike/aerospike-client-go
tests like example_listiter_int_test.go
which:
import the project with:
as "github.com/aerospike/aerospike-client-go"
use NewClient with the right prefix:
var v as.Value = as.NewValue(myListInt([]int{1, 2, 3}))
So don't forget to prefix NewClient
.
In your case:
import (
as "github.com/aerospike/aerospike-client-go"
"fmt"
)
And:
client, err := as.NewClient("127.0.0.1", 3000)
as
is an alias for the package name, since, as mentioned in "Call a function from another package in Go":
You import the package by its import path, and reference all its exported symbols (those starting with a capital letter) through the package name,
Since NewClient
is in client.go
of the package aerospike
, an alternative would be:
client, err := aerospike.NewClient("127.0.0.1", 3000)
Upvotes: 7