本文整理汇总了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
}
开发者ID:ringtail,项目名称:etcd,代码行数:31,代码来源:util.go
示例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
}
开发者ID:ringtail,项目名称:etcd,代码行数:35,代码来源:grpc_proxy.go
示例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)
}
开发者ID:RichardKnop,项目名称:go-oauth2-server,代码行数:31,代码来源:factory.go
示例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
}
开发者ID:micro,项目名称:go-plugins,代码行数:49,代码来源:etcdv3.go
示例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)
}
开发者ID:yorkart,项目名称:etcd-demo,代码行数:15,代码来源:etcd.go
示例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)
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:20,代码来源:cluster.go
示例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
}
开发者ID:CliffYuan,项目名称:etcd,代码行数:20,代码来源:util.go
示例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
}
开发者ID:lrita,项目名称:etcd,代码行数:39,代码来源:global.go
注:本文中的github.com/coreos/etcd/clientv3.Config类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论