Example #1
0
func mustCreateConn() *clientv3.Client {
	endpoint := endpoints[dialTotal%len(endpoints)]
	dialTotal++
	cfg := clientv3.Config{Endpoints: []string{endpoint}}
	if !tls.Empty() {
		cfgtls, err := tls.ClientConfig()
		if err != nil {
			fmt.Fprintf(os.Stderr, "bad tls config: %v\n", err)
			os.Exit(1)
		}
		cfg.TLS = cfgtls
	}

	if len(user) != 0 {
		splitted := strings.SplitN(user, ":", 2)
		if len(splitted) != 2 {
			fmt.Fprintf(os.Stderr, "bad user information: %s\n", user)
			os.Exit(1)
		}

		cfg.Username = splitted[0]
		cfg.Password = splitted[1]
	}

	client, err := clientv3.New(cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "dial error: %v\n", err)
		os.Exit(1)
	}
	return client
}
Example #2
0
func (p *ETCDConn) API(auth *Auth3) (*clientv3.Client, error) {
	cfg := clientv3.Config{
		Endpoints: p.endpoints,
		TLS:       p.t,

		// set timeout per request to fail fast when the target endpoint is unavailable
		DialTimeout: dialTimeout,
	}
	if auth != nil {
		cfg.Username = auth.UserName
		cfg.Password = auth.Password
	}

	return clientv3.New(cfg)
}