Example #1
0
func getEtcdClient(etcdURI string) etcdclient.EtcdClient {
	etcdClient, err := etcdclient.Dial(etcdURI)
	if err != nil {
		log.Panicln("Error with etcdclient.New", err.Error())
	}
	return etcdClient
}
Example #2
0
// Del deletes a key from etcd
func Del(uri, key string) error {
	client, err := etcdclient.Dial(uri)
	if err != nil {
		return err
	}

	return client.Del(key)
}
Example #3
0
// UpdateDirWithTTL updates the ttl on the dir
func UpdateDirWithTTL(uri, key string, ttlSeconds int) error {
	client, err := etcdclient.Dial(uri)
	if err != nil {
		return err
	}

	ttl := time.Duration(ttlSeconds) * time.Second
	return client.UpdateDirWithTTL(key, ttl)
}
Example #4
0
// Set sets a key on etcd, but only if its
// different
func Set(uri, key, value string) error {
	client, err := etcdclient.Dial(uri)
	if err != nil {
		return err
	}

	oldValue, err := client.Get(key)
	if err != nil {
		return err
	}

	if oldValue == value {
		return nil
	}

	return client.Set(key, value)
}