本文整理汇总了Golang中github.com/coreos/etcd/clientv3.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: mustCreateConn
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
}
示例2: newClientCfg
func newClientCfg() (*clientv3.Config, error) {
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tlsinfo := transport.TLSInfo{}
if grpcProxyCert != "" {
tlsinfo.CertFile = grpcProxyCert
cfgtls = &tlsinfo
}
if grpcProxyKey != "" {
tlsinfo.KeyFile = grpcProxyKey
cfgtls = &tlsinfo
}
if grpcProxyCA != "" {
tlsinfo.CAFile = grpcProxyCA
cfgtls = &tlsinfo
}
cfg := clientv3.Config{
Endpoints: grpcProxyEndpoints,
DialTimeout: 5 * time.Second,
}
if cfgtls != nil {
clientTLS, err := cfgtls.ClientConfig()
if err != nil {
return nil, err
}
cfg.TLS = clientTLS
}
// TODO: support insecure tls
return &cfg, nil
}
示例3: newEtcdClient
func newEtcdClient(theEndpoints, certFile, keyFile, caFile string) (*clientv3.Client, error) {
// Log the etcd endpoint for debugging purposes
logger.Infof("ETCD Endpoints: %s", theEndpoints)
// ETCD config
etcdConfig := clientv3.Config{
Endpoints: strings.Split(theEndpoints, ","),
DialTimeout: dialTimeout,
}
// Optionally, configure TLS transport
if certFile != "" && keyFile != "" && caFile != "" {
// Load client cert
tlsInfo := transport.TLSInfo{
CertFile: certFile,
KeyFile: keyFile,
TrustedCAFile: caFile,
}
// Setup HTTPS client
tlsConfig, err := tlsInfo.ClientConfig()
if err != nil {
return nil, err
}
// Add TLS config
etcdConfig.TLS = tlsConfig
}
// ETCD client
return clientv3.New(etcdConfig)
}
示例4: NewRegistry
func NewRegistry(opts ...registry.Option) registry.Registry {
config := clientv3.Config{
Endpoints: []string{"127.0.0.1:2379"},
}
var options registry.Options
for _, o := range opts {
o(&options)
}
if options.Timeout == 0 {
options.Timeout = 5 * time.Second
}
if options.Secure || options.TLSConfig != nil {
tlsConfig := options.TLSConfig
if tlsConfig == nil {
tlsConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
config.TLS = tlsConfig
}
var cAddrs []string
for _, addr := range options.Addrs {
if len(addr) == 0 {
continue
}
cAddrs = append(cAddrs, addr)
}
// if we got addrs then we'll update
if len(cAddrs) > 0 {
config.Endpoints = cAddrs
}
cli, _ := clientv3.New(config)
e := &etcdv3Registry{
client: cli,
options: options,
register: make(map[string]uint64),
leases: make(map[string]clientv3.LeaseID),
}
return e
}
示例5: API
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)
}
示例6: NewClientV3
// NewClientV3 creates a new grpc client connection to the member
func NewClientV3(m *member) (*clientv3.Client, error) {
if m.grpcAddr == "" {
return nil, fmt.Errorf("member not configured for grpc")
}
cfg := clientv3.Config{
Endpoints: []string{m.grpcAddr},
DialTimeout: 5 * time.Second,
}
if m.ClientTLSInfo != nil {
tls, err := m.ClientTLSInfo.ClientConfig()
if err != nil {
return nil, err
}
cfg.TLS = tls
}
return clientv3.New(cfg)
}
示例7: mustCreateConn
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
}
client, err := clientv3.New(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "dial error: %v\n", err)
os.Exit(1)
}
return client
}
示例8: mustClient
func mustClient(endpoints []string, cert, key, cacert string) *clientv3.Client {
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tls := transport.TLSInfo{}
var file string
if cert != "" {
tls.CertFile = cert
cfgtls = &tls
}
if key != "" {
tls.KeyFile = key
cfgtls = &tls
}
if cacert != "" {
tls.CAFile = file
cfgtls = &tls
}
cfg := clientv3.Config{
Endpoints: endpoints,
DialTimeout: 20 * time.Second,
}
if cfgtls != nil {
clientTLS, err := cfgtls.ClientConfig()
if err != nil {
ExitWithError(ExitBadArgs, err)
}
cfg.TLS = clientTLS
}
client, err := clientv3.New(cfg)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
return client
}