Can't launch aerospace example

I am trying to run an aerospeed 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 am getting the error:

Unresolved reference NewClient... 
and many more...

      

I ran the command:

go get github.com/aerospike/aerospike-client-go

      

and he downloaded the package to disk.

You can help?

+3


source to share


1 answer


You can see aerospike/aerospike-client-go

tests in the project such as example_listiter_int_test.go

that:

  • import the project with:

    as "github.com/aerospike/aerospike-client-go"
    
          

  • use NewClient with correct prefix:

    var v as.Value = as.NewValue(myListInt([]int{1, 2, 3}))
    
          

So don't forget the 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 because, as mentioned in " calling a function from another package in Go ":

You import the package by the import path and reference all of its exported symbols (those that start with a capital letter) through the package name,

Since it is in , the alternative would be: NewClient

client.go

package aerospike

client, err := aerospike.NewClient("127.0.0.1", 3000)

      

+7


source







All Articles