mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-02 05:14:25 +02:00
fix(rules): routes without default rule panics
This commit is contained in:
parent
4189ffa1db
commit
9d712b91ff
1 changed files with 11 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue