From 89bacedf3e88810388ba657e95f86f323691fa68 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 12 Jul 2013 08:44:40 -0700 Subject: [PATCH] change https bool to scheme string --- etcd.go | 4 ++-- transporter.go | 19 ++++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/etcd.go b/etcd.go index d3a964ac7..fbf868a70 100644 --- a/etcd.go +++ b/etcd.go @@ -268,7 +268,7 @@ func createTransporter(st int) transporter { switch st { case HTTP: - t.https = false + t.scheme = "http://" tr := &http.Transport{ Dial: dialTimeout, @@ -282,7 +282,7 @@ func createTransporter(st int) transporter { case HTTPS: fallthrough case HTTPSANDVERIFY: - t.https = true + t.scheme = "https://" tlsCert, err := tls.LoadX509KeyPair(serverCertFile, serverKeyFile) diff --git a/transporter.go b/transporter.go index f49047372..c68f062da 100644 --- a/transporter.go +++ b/transporter.go @@ -13,8 +13,8 @@ import ( // Transporter layer for communication between raft nodes type transporter struct { client *http.Client - // https - https bool + // scheme + scheme string } // Sends AppendEntries RPCs to a peer when the server is the leader. @@ -102,23 +102,12 @@ func (t transporter) GetLeaderClientAddress() string { // Send server side POST request func (t transporter) Post(path string, body io.Reader) (*http.Response, error) { - - if t.https { - resp, err := t.client.Post("https://"+path, "application/json", body) + resp, err := t.client.Post(t.scheme + path, "application/json", body) return resp, err - } else { - resp, err := t.client.Post("http://"+path, "application/json", body) - return resp, err - } } // Send server side GET request func (t transporter) Get(path string) (*http.Response, error) { - if t.https { - resp, err := t.client.Get("https://" + path) + resp, err := t.client.Get(t.scheme + path) return resp, err - } else { - resp, err := t.client.Get("http://" + path) - return resp, err - } }