本文整理匯總了Golang中github.com/coreos/etcd/pkg/transport.TLSInfo.CertFile方法的典型用法代碼示例。如果您正苦於以下問題:Golang TLSInfo.CertFile方法的具體用法?Golang TLSInfo.CertFile怎麽用?Golang TLSInfo.CertFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/etcd/pkg/transport.TLSInfo
的用法示例。
在下文中一共展示了TLSInfo.CertFile方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mustClient
func mustClient(endpoint, 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: []string{endpoint},
TLS: cfgtls,
DialTimeout: 20 * time.Second,
}
client, err := clientv3.New(cfg)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
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: newClientCfg
func newClientCfg(endpoints []string, dialTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) {
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tlsinfo := transport.TLSInfo{}
if scfg.cert != "" {
tlsinfo.CertFile = scfg.cert
cfgtls = &tlsinfo
}
if scfg.key != "" {
tlsinfo.KeyFile = scfg.key
cfgtls = &tlsinfo
}
if scfg.cacert != "" {
tlsinfo.CAFile = scfg.cacert
cfgtls = &tlsinfo
}
cfg := &clientv3.Config{
Endpoints: endpoints,
DialTimeout: dialTimeout,
}
if cfgtls != nil {
clientTLS, err := cfgtls.ClientConfig()
if err != nil {
return nil, err
}
cfg.TLS = clientTLS
}
// if key/cert is not given but user wants secure connection, we
// should still setup an empty tls configuration for gRPC to setup
// secure connection.
if cfg.TLS == nil && !scfg.insecureTransport {
cfg.TLS = &tls.Config{}
}
// If the user wants to skip TLS verification then we should set
// the InsecureSkipVerify flag in tls configuration.
if scfg.insecureSkipVerify && cfg.TLS != nil {
cfg.TLS.InsecureSkipVerify = true
}
if acfg != nil {
cfg.Username = acfg.username
cfg.Password = acfg.password
}
return cfg, nil
}
示例4: mustClient
func mustClient(cmd *cobra.Command) *clientv3.Client {
endpoint, err := cmd.Flags().GetString("endpoint")
if err != nil {
ExitWithError(ExitError, err)
}
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tls := transport.TLSInfo{}
var file string
if file, err = cmd.Flags().GetString("cert"); err == nil && file != "" {
tls.CertFile = file
cfgtls = &tls
} else if cmd.Flags().Changed("cert") {
ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cert option"))
}
if file, err = cmd.Flags().GetString("key"); err == nil && file != "" {
tls.KeyFile = file
cfgtls = &tls
} else if cmd.Flags().Changed("key") {
ExitWithError(ExitBadArgs, errors.New("empty string is passed to --key option"))
}
if file, err = cmd.Flags().GetString("cacert"); err == nil && file != "" {
tls.CAFile = file
cfgtls = &tls
} else if cmd.Flags().Changed("cacert") {
ExitWithError(ExitBadArgs, errors.New("empty string is passed to --cacert option"))
}
cfg := clientv3.Config{
Endpoints: []string{endpoint},
TLS: cfgtls,
DialTimeout: 20 * time.Second,
}
client, err := clientv3.New(cfg)
if err != nil {
ExitWithError(ExitBadConnection, err)
}
return client
}