MCPcopy
hub / github.com/go-kit/kit / NewClient

Function NewClient

sd/etcdv3/client.go:89–131  ·  view source on GitHub ↗

NewClient returns Client with a connection to the named machines. It will return an error if a connection to the cluster cannot be made.

(ctx context.Context, machines []string, options ClientOptions)

Source from the content-addressed store, hash-verified

87// NewClient returns Client with a connection to the named machines. It will
88// return an error if a connection to the cluster cannot be made.
89func NewClient(ctx context.Context, machines []string, options ClientOptions) (Client, error) {
90 if options.DialTimeout == 0 {
91 options.DialTimeout = 3 * time.Second
92 }
93 if options.DialKeepAlive == 0 {
94 options.DialKeepAlive = 3 * time.Second
95 }
96
97 var err error
98 var tlscfg *tls.Config
99
100 if options.Cert != "" && options.Key != "" {
101 tlsInfo := transport.TLSInfo{
102 CertFile: options.Cert,
103 KeyFile: options.Key,
104 TrustedCAFile: options.CACert,
105 }
106 tlscfg, err = tlsInfo.ClientConfig()
107 if err != nil {
108 return nil, err
109 }
110 }
111
112 cli, err := clientv3.New(clientv3.Config{
113 Context: ctx,
114 Endpoints: machines,
115 DialTimeout: options.DialTimeout,
116 DialKeepAliveTime: options.DialKeepAlive,
117 DialOptions: options.DialOptions,
118 TLS: tlscfg,
119 Username: options.Username,
120 Password: options.Password,
121 })
122 if err != nil {
123 return nil, err
124 }
125
126 return &client{
127 cli: cli,
128 ctx: ctx,
129 kv: clientv3.NewKV(cli),
130 }, nil
131}
132
133func (c *client) LeaseID() int64 { return int64(c.leaseID) }
134

Callers 6

TestNewClientFunction · 0.70
TestClientOptionsFunction · 0.70
ExampleFunction · 0.70
TestIntegrationFunction · 0.70
TestIntegrationTTLFunction · 0.70

Calls

no outgoing calls

Tested by 6

TestNewClientFunction · 0.56
TestClientOptionsFunction · 0.56
ExampleFunction · 0.56
TestIntegrationFunction · 0.56
TestIntegrationTTLFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…