change https bool to scheme string

This commit is contained in:
Xiang Li
2013-07-12 08:44:40 -07:00
parent e6354cdccf
commit 89bacedf3e
2 changed files with 6 additions and 17 deletions

View File

@@ -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)

View File

@@ -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
}
}