Skip to content

Commit

Permalink
Issue #438: Do not add separators for NoRouteHTML page
Browse files Browse the repository at this point in the history
This patch ensures that the NoRoute HTML page is returned
without additional separators as they are used for routing
table fragments.

This is a regression from 1.5.7.

Fixes #438
  • Loading branch information
magiconair committed Feb 11, 2018
1 parent 759056a commit 006c3d2
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 006c3d2

Please sign in to comment.