Documentation
¶
Overview ¶
Package etcdutil helps implementation of the common specification to take etcd connection parameters.
To read parameters from YAML (or JSON):
import ( "github.com/cybozu-go/etcdutil" "sigs.k8s.io/yaml" ) func main() { cfg := etcdutil.NewConfig("/key-prefix/") err := yaml.Unmarshal(data, cfg) if err != nil { panic(err) } etcd, err := etcdutil.NewClient(cfg) if err != nil { panic(err) } defer etcd.Close() // use etcd; it is a etcd *clientv3.Client object. }
To read parameters from command-line flags:
import ( "flag" "github.com/cybozu-go/etcdutil" ) func main() { cfg := etcdutil.NewConfig("/key-prefix/") cfg.AddFlags(flag.CommandLine) flag.Parse() etcd, err := etcdutil.NewClient(cfg) if err != nil { panic(err) } defer etcd.Close() // use etcd; it is a etcd *clientv3.Client object. }
Index ¶
Constants ¶
View Source
const (
// DefaultTimeout is default etcd connection timeout.
DefaultTimeout = "2s"
)
Variables ¶
View Source
var ( // DefaultEndpoints is default etcd servers. DefaultEndpoints = []string{"http://127.0.0.1:2379"} )
Functions ¶
Types ¶
type Config ¶
type Config struct { // Endpoints are etcd servers. Endpoints []string `json:"endpoints" toml:"endpoints"` // Prefix is etcd prefix key. Prefix string `json:"prefix" toml:"prefix"` // Timeout is dial timeout of the etcd client connection. Timeout string `json:"timeout" toml:"timeout"` // Username is username for loging in to the etcd. Username string `json:"username" toml:"username"` // Password is password for loging in to the etcd. Password string `json:"password" toml:"password"` // TLSCAFile is root CA path. TLSCAFile string `json:"tls-ca-file" toml:"tls-ca-file"` // TLSCA is root CA raw string. TLSCA string `json:"tls-ca" toml:"tls-ca"` // TLSCertFile is TLS client certificate path. TLSCertFile string `json:"tls-cert-file" toml:"tls-cert-file"` // TLSCert is TLS client certificate raw string. TLSCert string `json:"tls-cert" toml:"tls-cert"` // TLSKeyFile is TLS client private key. TLSKeyFile string `json:"tls-key-file" toml:"tls-key-file"` // TLSKey is TLS client private key raw string. TLSKey string `json:"tls-key" toml:"tls-key"` }
Config represents configuration parameters to access etcd.
Click to show internal directories.
Click to hide internal directories.