Skip to content

Commit c39a561

Browse files
committed
fix(etcd.go): workaround missing env var
“url” wasn’t found in the given params, so I’ve worked around it here
1 parent 7cb8186 commit c39a561

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

pkg/etcd/etcd.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -22,6 +23,12 @@ var (
2223
retrySleep = 200 * time.Millisecond
2324
)
2425

26+
const (
27+
hostEnvVar = "DEIS_ETCD_1_SERVICE_HOST"
28+
portEnvVar = "DEIS_ETCD_1_SERVICE_PORT_CLIENT"
29+
defaultHost = "http://localhost"
30+
)
31+
2532
// Getter describes the Get behavior of an Etcd client.
2633
//
2734
// Usually you will want to use go-etcd/etcd.Client to satisfy this.
@@ -64,7 +71,19 @@ type GetterSetter interface {
6471
// Returns:
6572
// This puts an *etcd.Client into the context.
6673
func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
67-
url := p.Get("url", "http://localhost:4001").(string)
74+
host := os.Getenv(hostEnvVar)
75+
port, err := strconv.Atoi(os.Getenv(portEnvVar))
76+
if host == "" {
77+
host = defaultHost
78+
}
79+
if err != nil {
80+
port = 4001
81+
}
82+
83+
// Aaron(12/9/2015): to shame me into fixing this later, but it's a bigger change
84+
fmt.Println("Aaron hasn't fixed the env var collection stage in the cookoo route yet...")
85+
// url := p.Get("url", "http://localhost:4001").(string)
86+
url := fmt.Sprintf("%s:%d", host, port)
6887

6988
// Backed this out because it's unnecessary so far.
7089
//hosts := p.Get("urls", []string{"http://localhost:4001"}).([]string)

0 commit comments

Comments
 (0)