MCPcopy Index your code
hub / github.com/koding/kite / NewEtcd

Function NewEtcd

kontrol/etcd.go:35–76  ·  view source on GitHub ↗
(machines []string, log kite.Logger)

Source from the content-addressed store, hash-verified

33}
34
35func NewEtcd(machines []string, log kite.Logger) *Etcd {
36 if machines == nil || len(machines) == 0 {
37 machines = []string{"http://127.0.0.1:2379"}
38 }
39
40 cfg := etcd.Config{
41 Endpoints: machines,
42 Transport: etcd.DefaultTransport,
43 HeaderTimeoutPerRequest: time.Second,
44 }
45
46 client, err := etcd.New(cfg)
47 if err != nil {
48 panic("cannot connect to etcd cluster: " + strings.Join(machines, ","))
49 }
50
51 e := &Etcd{
52 client: NewKeysAPILogger(etcd.NewKeysAPI(client), log),
53 log: log,
54 }
55
56 // Create our prefix as a directory if it does not exist
57 _, err = e.client.Get(context.Background(), KitesPrefix, nil)
58 if err == nil {
59 return e
60 }
61
62 _, err = e.client.Set(
63 context.Background(),
64 KitesPrefix,
65 "",
66 &etcd.SetOptions{
67 Dir: true,
68 PrevExist: etcd.PrevIgnore,
69 },
70 )
71 if err != nil {
72 log.Fatal("Could not create KitesPrefix %q: %v", KitesPrefix, err)
73 }
74
75 return e
76}
77
78func (e *Etcd) Delete(k *protocol.Kite) error {
79 etcdKey := KitesPrefix + k.String()

Callers 3

BenchmarkEtcdAddFunction · 0.85
BenchmarkEtcdGetFunction · 0.85
startKontrolFunction · 0.85

Calls 4

NewKeysAPILoggerFunction · 0.85
FatalMethod · 0.80
GetMethod · 0.65
SetMethod · 0.45

Tested by 3

BenchmarkEtcdAddFunction · 0.68
BenchmarkEtcdGetFunction · 0.68
startKontrolFunction · 0.68