MatchWithError returns true if r matches m.
(r *http.Request)
| 369 | |
| 370 | // MatchWithError returns true if r matches m. |
| 371 | func (mset MatcherSet) MatchWithError(r *http.Request) (bool, error) { |
| 372 | for _, m := range mset { |
| 373 | if me, ok := m.(RequestMatcherWithError); ok { |
| 374 | match, err := me.MatchWithError(r) |
| 375 | if err != nil || !match { |
| 376 | return match, err |
| 377 | } |
| 378 | continue |
| 379 | } |
| 380 | if me, ok := m.(RequestMatcher); ok { |
| 381 | if !me.Match(r) { |
| 382 | // for backwards compatibility |
| 383 | err, ok := GetVar(r.Context(), MatcherErrorVarKey).(error) |
| 384 | if ok { |
| 385 | // clear out the error from context since we've consumed it |
| 386 | SetVar(r.Context(), MatcherErrorVarKey, nil) |
| 387 | return false, err |
| 388 | } |
| 389 | return false, nil |
| 390 | } |
| 391 | continue |
| 392 | } |
| 393 | return false, fmt.Errorf("matcher is not a RequestMatcher or RequestMatcherWithError: %#v", m) |
| 394 | } |
| 395 | return true, nil |
| 396 | } |
| 397 | |
| 398 | // RawMatcherSets is a group of matcher sets |
| 399 | // in their raw, JSON form. |
nothing calls this directly
no test coverage detected