etcd.go 517 B

123456789101112131415161718192021222324252627282930
  1. package etcd
  2. import (
  3. "github.com/coreos/etcd/clientv3"
  4. "time"
  5. )
  6. type EtcdClient struct {
  7. c *clientv3.Client
  8. }
  9. func Connect(servers []string, username, password string, timeout time.Duration) (*EtcdClient, error) {
  10. etcd := &EtcdClient{}
  11. var err error
  12. conf := clientv3.Config{
  13. Endpoints:servers,
  14. DialTimeout: timeout,
  15. }
  16. if len(username) > 0 {
  17. conf.Username = username
  18. conf.Password = password
  19. }
  20. etcd.c, err = clientv3.New(conf)
  21. return etcd, err
  22. }
  23. func (self *EtcdClient) Put() {
  24. self.c.Put()
  25. }