Skip to content

Instantly share code, notes, and snippets.

@ueokande
Created August 27, 2018 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ueokande/85f3d323547fd63eb70d3a6a0e36cbe1 to your computer and use it in GitHub Desktop.
Save ueokande/85f3d323547fd63eb70d3a6a0e36cbe1 to your computer and use it in GitHub Desktop.
etcd test
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/coreos/etcd/clientv3"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"http://example.com:2379"},
DialTimeout: 2 * time.Second,
})
if err != nil {
fmt.Fprintln(os.Stderr, "[initialize etcd client]", err)
return
}
defer cli.Close()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
resp, err := cli.MemberList(ctx)
if err != nil {
fmt.Fprintln(os.Stderr, "[getting etcd members]", err)
return
}
fmt.Fprintln(os.Stdout, "current member count =", len(resp.Members))
}
@ueokande
Copy link
Author

Using etcd on v3.3.9:

$ go run main.go
[initialize etcd client] context deadline exceeded

Using etcd on master (af85949b)

$ go run main.go
[getting etcd members] context deadline exceeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment