Disable router when a rule has an error

This commit is contained in:
Ludovic Fernandez
2020-12-17 10:06:03 +01:00
committed by GitHub
parent ac8e47579b
commit 63f65e5b2a
3 changed files with 41 additions and 1 deletions
+8 -1
View File
@@ -59,7 +59,14 @@ func (r *Router) AddRoute(rule string, priority int, handler http.Handler) error
}
route := r.NewRoute().Handler(handler).Priority(priority)
return addRuleOnRoute(route, buildTree())
err = addRuleOnRoute(route, buildTree())
if err != nil {
route.BuildOnly()
return err
}
return nil
}
type tree struct {
+10
View File
@@ -29,6 +29,16 @@ func Test_addRoute(t *testing.T) {
rule: "rulewithnotmatcher",
expectedError: true,
},
{
desc: "Host empty",
rule: "Host(``)",
expectedError: true,
},
{
desc: "PathPrefix empty",
rule: "PathPrefix(``)",
expectedError: true,
},
{
desc: "PathPrefix",
rule: "PathPrefix(`/foo`)",