Skip to content

Commit

Permalink
Merge pull request #441 from fabiolb/issue-438-noroutehtmlpath-has-se…
Browse files Browse the repository at this point in the history
…parators

Issue #438: Do not add separators for NoRouteHTML page
  • Loading branch information
magiconair committed Feb 18, 2018
2 parents 9b27ff1 + 006c3d2 commit cc99a9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions registry/consul/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ func (b *be) WatchManual() chan string {
log.Printf("[INFO] consul: Watching KV path %q", b.cfg.KVPath)

kv := make(chan string)
go watchKV(b.c, b.cfg.KVPath, kv)
go watchKV(b.c, b.cfg.KVPath, kv, true)
return kv
}

func (b *be) WatchNoRouteHTML() chan string {
log.Printf("[INFO] consul: Watching KV path %q", b.cfg.NoRouteHTMLPath)

html := make(chan string)
go watchKV(b.c, b.cfg.NoRouteHTMLPath, html)
go watchKV(b.c, b.cfg.NoRouteHTMLPath, html, false)
return html
}

Expand Down
11 changes: 7 additions & 4 deletions registry/consul/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

// watchKV monitors a key in the KV store for changes.
// The intended use case is to add additional route commands to the routing table.
func watchKV(client *api.Client, path string, config chan string) {
func watchKV(client *api.Client, path string, config chan string, separator bool) {
var lastIndex uint64
var lastValue string

for {
value, index, err := listKV(client, path, lastIndex)
value, index, err := listKV(client, path, lastIndex, separator)
if err != nil {
log.Printf("[WARN] consul: Error fetching config from %s. %v", path, err)
time.Sleep(time.Second)
Expand Down Expand Up @@ -46,7 +46,7 @@ func listKeys(client *api.Client, path string, waitIndex uint64) ([]string, uint
return keys, meta.LastIndex, nil
}

func listKV(client *api.Client, path string, waitIndex uint64) (string, uint64, error) {
func listKV(client *api.Client, path string, waitIndex uint64, separator bool) (string, uint64, error) {
q := &api.QueryOptions{RequireConsistent: true, WaitIndex: waitIndex}
kvpairs, meta, err := client.KV().List(path, q)
if err != nil {
Expand All @@ -57,7 +57,10 @@ func listKV(client *api.Client, path string, waitIndex uint64) (string, uint64,
}
var s []string
for _, kvpair := range kvpairs {
val := "# --- " + kvpair.Key + "\n" + strings.TrimSpace(string(kvpair.Value))
val := strings.TrimSpace(string(kvpair.Value))
if separator {
val = "# --- " + kvpair.Key + "\n" + val
}
s = append(s, val)
}
return strings.Join(s, "\n\n"), meta.LastIndex, nil
Expand Down

0 comments on commit cc99a9b

Please sign in to comment.