Swith to coreos/go-log from ccding/go-logging

bump(github.com/coreos/go-etcd): 57864cf81c66b8605816fafab3ab142e1c5f5b29
bump(github.com/coreos/go-log/log):
bump(github.com/coreos/go-systemd): 52f153170a52158deffce83502a9b6aed3744802
This commit is contained in:
David Fisher
2013-09-25 13:16:07 -07:00
parent 940294d1cd
commit 951d467917
34 changed files with 811 additions and 1790 deletions

View File

@ -2,4 +2,49 @@
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](https://github.com/coreos/etcd) for details on the client protocol.
This etcd client library is under heavy development. Check back soon for more
docs. In the meantime, check out [etcd](https://github.com/coreos/etcd) for
details on the client protocol.
For usage see example below or look at godoc: [go-etcd/etcd](http://godoc.org/github.com/coreos/go-etcd/etcd)
## Install
```bash
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.
```go
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: *store.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: []*store.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: *store.Response
res, _ = c.Delete("foo")
fmt.Printf("delete response: %+v\n", res)
}
```

View File

@ -40,10 +40,9 @@ func NewClient() *Client {
// default leader and machines
cluster := Cluster{
Leader: "http://0.0.0.0:4001",
Machines: make([]string, 1),
Leader: "http://127.0.0.1:4001",
Machines: []string{"http://127.0.0.1:4001"},
}
cluster.Machines[0] = "http://0.0.0.0:4001"
config := Config{
// default use http
@ -117,7 +116,7 @@ func (c *Client) SyncCluster() bool {
// sync cluster information by providing machine list
func (c *Client) internalSyncCluster(machines []string) bool {
for _, machine := range machines {
httpPath := c.createHttpPath(machine, "v1/machines")
httpPath := c.createHttpPath(machine, version+"/machines")
resp, err := c.httpClient.Get(httpPath)
if err != nil {
// try another machine in the cluster
@ -236,11 +235,12 @@ func (c *Client) sendRequest(method string, _path string, body string) (*http.Re
// try to connect the leader
continue
} else if resp.StatusCode == http.StatusInternalServerError {
resp.Body.Close()
retry++
if retry > 2*len(c.cluster.Machines) {
return nil, errors.New("Cannot reach servers")
}
resp.Body.Close()
continue
} else {
logger.Debug("send.return.response ", httpPath)

View File

@ -1,19 +1,27 @@
package etcd
import (
"github.com/ccding/go-logging/logging"
"github.com/coreos/go-log/log"
"os"
)
var logger, _ = logging.SimpleLogger("go-etcd")
var logger *log.Logger
func init() {
logger.SetLevel(logging.FATAL)
setLogger(log.PriErr)
}
func OpenDebug() {
logger.SetLevel(logging.NOTSET)
setLogger(log.PriDebug)
}
func CloseDebug() {
logger.SetLevel(logging.FATAL)
setLogger(log.PriErr)
}
func setLogger(priority log.Priority) {
logger = log.NewSimple(
log.PriorityFilter(
priority,
log.WriterSink(os.Stdout, log.BasicFormat, log.BasicFields)))
}

View File

@ -1,3 +1,3 @@
package etcd
var version = "v1"
const version = "v1"