<commit_before>package etcd

import (
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"net/url"
	"regexp"
	"strconv"

	etcd2 "github.com/coreos/go-etcd/etcd"
	"github.com/gliderlabs/registrator/bridge"
	etcd "gopkg.in/coreos/go-etcd.v0/etcd"
)

func init() {
	bridge.Register(new(Factory), "etcd")
}

type Factory struct{}

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, "http://"+uri.Host)
	} else {
		urls = append(urls, "http://127.0.0.1:4001")
	}

	res, err := http.Get(urls[0] + "/version")
	if err != nil {
		log.Fatal("etcd: error retrieving version", err)
	}

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)<commit_msg>Added etcds adapter for using etcd via tls<commit_after>package etcd

import (
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"net/url"
	"regexp"
	"strconv"
	"os"

	etcd2 "github.com/coreos/go-etcd/etcd"
	"github.com/gliderlabs/registrator/bridge"
	etcd "gopkg.in/coreos/go-etcd.v0/etcd"
)

func init() {
  bridge.Register(&Factory{Scheme: "http"}, "etcd")
  bridge.Register(&Factory{Scheme: "https"}, "etcds")
}

type Factory struct{
  Scheme string
}

func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
	urls := make([]string, 0)
	if uri.Host != "" {
		urls = append(urls, f.Scheme+"://"+uri.Host)
	} else {
		urls = append(urls, f.Scheme+"://127.0.0.1:4001")
	}

  if f.Scheme == "https" {
    cert := os.Getenv("ETCD_CERTFILE")
    key := os.Getenv("ETCD_KEYFILE")
    caCert := os.Getenv("ETCD_CAFILE")
    client, err := etcd2.NewTLSClient(urls, cert, key, caCert)
    if err != nil {
      log.Fatal("etcd: error creating tls client", err)
    }
    return &EtcdAdapter{client2: client, path: uri.Path}
  }

	res, err := http.Get(urls[0] + "/version")
	if err != nil {
		log.Fatal("etcd: error retrieving version", err)
	}

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)
{'fraction_non_alphanumeric': 0.1869109947643979, 'fraction_numerical': 0.015706806282722512, 'mean_word_length': 3.753731343283582, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1243749', 'n_tokens_mistral': 828, 'n_tokens_neox': 805, 'n_words': 154}