docker / libkv

Distributed key/value store abstraction library
Apache License 2.0
853 stars 205 forks source link

cycle error #126

Closed odedlaz closed 8 years ago

odedlaz commented 8 years ago

I just tried compiling the example, and I get a cycle error:

import cycle not allowed
package github.com/odedlaz/hello
    imports github.com/docker/libkv
    imports github.com/docker/libkv/store/boltdb
    imports github.com/docker/libkv

this is the code I used:

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/docker/libkv"
    "github.com/docker/libkv/store"
    "github.com/docker/libkv/store/boltdb"
    "github.com/docker/libkv/store/consul"
    "github.com/docker/libkv/store/etcd"
    "github.com/docker/libkv/store/zookeeper"
)

func init() {
    // Register consul store to libkv
    consul.Register()

    // We can register as many backends that are supported by libkv
    etcd.Register()
    zookeeper.Register()
    boltdb.Register()
}

func main() {
    client := "localhost:8500"

    // Initialize a new store with consul
    kv, err := libkv.NewStore(
        store.CONSUL, // or "consul"
        []string{client},
        &store.Config{
            ConnectionTimeout: 10 * time.Second,
        },
    )
    if err != nil {
        log.Fatal("Cannot create store consul")
    }

    key := "foo"
    err = kv.Put(key, []byte("bar"), nil)
    if err != nil {
        fmt.Errorf("Error trying to put value at key: %v", key)
    }

    pair, err := kv.Get(key)
    if err != nil {
        fmt.Errorf("Error trying accessing value at key: %v", key)
    }

    err = kv.Delete(key)
    if err != nil {
        fmt.Errorf("Error trying to delete key %v", key)
    }

    log.Info("value: ", string(pair.Value))
}
abronan commented 8 years ago

Hi @odedlaz, thanks for reporting the issue. Strange, I can compile and run the example just fine here. Is it with master?

Also, what happens if you remove the boltdb.Register()?

odedlaz commented 8 years ago

@abronan still doesn't work. I removed the entire directory, cloned the repo and it worked... :| thanks for the quick response!