Disable router when a rule has an error
This commit is contained in:
parent
ac8e47579b
commit
63f65e5b2a
3 changed files with 41 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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`)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue