Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 595 watchbackend #629

Merged
merged 11 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ func watchBackend(cfg *config.Config, first chan bool) {
svccfg string
mancfg string
customBE string
next bytes.Buffer

once sync.Once
)
Expand All @@ -454,19 +455,21 @@ func watchBackend(cfg *config.Config, first chan bool) {
man := registry.Default.WatchManual()

for {

select {
case svccfg = <-svc:
case mancfg = <-man:
}

// manual config overrides service config
// order matters
next := svccfg + "\n" + mancfg
if next == last {
next.Reset()
next.WriteString(svccfg)
next.WriteString("\n")
next.WriteString(mancfg)
aaronhurt marked this conversation as resolved.
Show resolved Hide resolved
if next.String() == last {
continue
}

aliases, err := route.ParseAliases(next)
aliases, err := route.ParseAliases(next.String())
if err != nil {
log.Printf("[WARN]: %s", err)
}
Expand All @@ -478,14 +481,11 @@ func watchBackend(cfg *config.Config, first chan bool) {
continue
}
route.SetTable(t)
logRoutes(t, last, next, cfg.Log.RoutesFormat)
last = next

logRoutes(t, last, next.String(), cfg.Log.RoutesFormat)
last = next.String()
once.Do(func() { close(first) })
}

}

}

func watchNoRouteHTML(cfg *config.Config) {
Expand Down
25 changes: 14 additions & 11 deletions route/parse_new.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package route

import (
"bufio"
"bytes"
"errors"
"fmt"
"regexp"
Expand Down Expand Up @@ -65,25 +67,26 @@ route weight service host/path weight w tags "tag1,tag2"
// The commands are parsed in order and order matters.
// Deleting a route that has not been created yet yields
// a different result than the other way around.
func Parse(in string) (defs []*RouteDef, err error) {
func Parse(in bytes.Buffer) (defs []*RouteDef, err error) {
var def *RouteDef
for i, s := range strings.Split(in, "\n") {
scanner := bufio.NewScanner(&in)
for scanner.Scan() {
def, err = nil, nil
s = strings.TrimSpace(s)
result := strings.TrimSpace(scanner.Text())
switch {
case reComment.MatchString(s) || reBlankLine.MatchString(s):
case reComment.MatchString(result) || reBlankLine.MatchString(result):
continue
case reRouteAdd.MatchString(s):
def, err = parseRouteAdd(s)
case reRouteDel.MatchString(s):
def, err = parseRouteDel(s)
case reRouteWeight.MatchString(s):
def, err = parseRouteWeight(s)
case reRouteAdd.MatchString(result):
def, err = parseRouteAdd(result)
case reRouteDel.MatchString(result):
def, err = parseRouteDel(result)
case reRouteWeight.MatchString(result):
def, err = parseRouteWeight(result)
default:
err = errors.New("syntax error: 'route' expected")
}
if err != nil {
return nil, fmt.Errorf("line %d: %s", i+1, err)
return nil, fmt.Errorf("line %d: %s", err)
}
defs = append(defs, def)
}
Expand Down
3 changes: 1 addition & 2 deletions route/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func hostpath(prefix string) (host string, path string) {
return p[0], "/" + p[1]
}

func NewTable(s string) (t Table, err error) {

func NewTable(s bytes.Buffer) (t Table, err error) {
defs, err := Parse(s)
if err != nil {
return nil, err
Expand Down