This is a creation in Article, where the information may have evolved or changed.
Etcd and Consul are very well-known service governance tools. This article first to discuss the use of ETCD.
Learn to use
Installation
go get github.com/coreos/etcd/client
Reference
"github.com/coreos/etcd/client"
Example
cfg := client.Config{ Endpoints: []string{"http://127.0.0.1:2379"}, Transport: client.DefaultTransport, // set timeout per request to fail fast when the target endpoint is unavailable HeaderTimeoutPerRequest: time.Second,}c, err := client.New(cfg)if err != nil { log.Fatal(err)}
Instructions for use
Create Client
c, err := client.New(cfg)if err != nil { log.Fatal(err)}
Setting up the configuration
kapi := client.NewKeysAPI(c)log.Print("Setting '/foo' key with 'bar' value")resp, err := kapi.Set(context.Background(), "/foo", "bar", nil)if err != nil { log.Fatal(err)} else { log.Printf("Set is done. Metadata is %q\n", resp)}
Read configuration
kapi := client.NewKeysAPI(c)resp, err = kapi.Get(context.Background(), "/foo", nil)if err != nil { log.Fatal(err)} else { log.Printf("Get is done. Metadata is %q\n", resp) log.Printf("%q key has %q value\n", resp.Node.Key, resp.Node.Value)}
Subscription configuration changes