diff --git a/etcd_client.go b/etcd_client.go index aa721ff25fdb70bfc02f2fe59cd5eed8e59b6078..551c188d73ad90196e78d3b456d4198e2c6c39eb 100644 --- a/etcd_client.go +++ b/etcd_client.go @@ -4,14 +4,13 @@ import ( "flag" "io/ioutil" "log" - "net" "strings" "git.autistici.org/ale/autoradio/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd" ) var ( - etcdMachines = flag.String("etcd-servers", "localhost:2379", "Etcd servers (comma-separated list)") + etcdMachines = flag.String("etcd-servers", "http://127.0.0.1:2379", "Etcd server URLs (comma-separated list)") etcdCertFile = flag.String("etcd-cert", "", "SSL certificate for etcd client") etcdKeyFile = flag.String("etcd-key", "", "SSL private key for etcd client") etcdCaFile = flag.String("etcd-ca", "", "SSL CA certificate for etcd client") @@ -25,45 +24,19 @@ func mustLoadFile(path string) string { return string(data) } -// Resolve a list of etcd host:port specs, returning URLs. -func resolveAll(input []string, proto string) []string { - var result []string - for _, hostport := range input { - host, port, err := net.SplitHostPort(hostport) - if err != nil { - log.Fatalf("Error parsing etcd server spec '%s': %s", hostport, err) - } - addrs, err := net.LookupHost(host) - if err != nil { - log.Fatalf("Error resolving etcd server spec '%s': %s", hostport, err) - } - for _, a := range addrs { - url := proto + "://" + net.JoinHostPort(a, port) - result = append(result, url) - } - } - return result -} - // NewEtcdClient creates a new etcd client. It uses command-line flags // to find servers and connection parameters. If the 'strongReads' // argument is true, read requests will also be sent to the etcd // master and should be able to see the effect of previous writes. func NewEtcdClient(strongReads bool) EtcdClient { - proto := "http" - if *etcdCertFile != "" && *etcdKeyFile != "" { - proto = "https" - } - - // Resolve etcd servers. - machines := resolveAll(strings.Split(*etcdMachines, ","), proto) - if len(machines) == 0 { + machines := strings.Split(*etcdMachines, ",") + if len(machines) < 1 { log.Fatal("No etcd servers specified!") } // Create the etcd client. var c *etcd.Client - if proto == "https" { + if *etcdCertFile != "" && *etcdKeyFile != "" { var err error c, err = etcd.NewTLSClient(machines, mustLoadFile(*etcdCertFile),