/go-etcd

Go client library for etcd

Primary LanguageGoApache License 2.0Apache-2.0

go-etcd

golang client library for etcd

This etcd client library is under heavy development. Check back soon for more docs. In the meantime, check out etcd for details on the client protocol.

For usage see example below or look at godoc: go-etcd/etcd

Install

go get github.com/coreos/go-etcd/etcd

Examples

Returning error values are not showed for the sake of simplicity, but you should check them.

package main

import (
	"fmt"
	"github.com/coreos/go-etcd/etcd"
)

func main() {
	c := etcd.NewClient() // default binds to http://0.0.0.0:4001

	// SET the value "bar" to the key "foo" with zero TTL
	// returns a: *Response
	res, _ := c.Set("foo", "bar", 0)
	fmt.Printf("set response: %+v\n", res)

	// GET the value that is stored for the key "foo"
	// return a slice: []*Response
	values, _ := c.Get("foo")
	for i, res := range values { // .. and print them out
		fmt.Printf("[%d] get response: %+v\n", i, res)
	}

	// DELETE the key "foo"
	// returns a: *Response
	res, _ = c.Delete("foo")
	fmt.Printf("delete response: %+v\n", res)
}