mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 07:24:31 +01:00
fix(rules): routes without default rule panics
This commit is contained in:
@@ -54,7 +54,13 @@ type (
|
||||
// if no rule matches and default rule is not set,
|
||||
// the request is passed to the upstream.
|
||||
func (rules Rules) BuildHandler(caller string, up http.Handler) http.HandlerFunc {
|
||||
var defaultRule *Rule
|
||||
defaultRule := &Rule{
|
||||
Name: "default",
|
||||
Do: Command{
|
||||
raw: "pass",
|
||||
exec: BypassCommand{},
|
||||
},
|
||||
}
|
||||
|
||||
nonDefaultRules := make(Rules, 0, len(rules))
|
||||
for i, rule := range rules {
|
||||
@@ -79,6 +85,10 @@ func (rules Rules) BuildHandler(caller string, up http.Handler) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
if len(nonDefaultRules) == 0 {
|
||||
nonDefaultRules = rules
|
||||
}
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
cache := NewCache()
|
||||
defer cache.Release()
|
||||
|
||||
Reference in New Issue
Block a user