| 1 | // Copyright 2016 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package servemuxscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/ |
| 16 | |
| 17 | import "net/httpscip-go gomod github.com/golang/go/src go1.11 `net/http`/" |
| 18 | |
| 19 | // Matcher is a conditional evaluator of request urls against patterns registered |
| 20 | // in mux. |
| 21 | type Matcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher# struct { |
| 22 | muxscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#mux. *httpscip-go gomod github.com/golang/go/src go1.11 `net/http`/.ServeMuxscip-go gomod github.com/golang/go/src go1.11 `net/http`/ServeMux# |
| 23 | } |
| 24 | |
| 25 | // NewMatcher builds a new servemux.Matcher. |
| 26 | func NewMatcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/NewMatcher().(mux *httpscip-go gomod github.com/golang/go/src go1.11 `net/http`/.ServeMuxscip-go gomod github.com/golang/go/src go1.11 `net/http`/ServeMux#) *Matcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher# { |
| 27 | return &Matcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#{ |
| 28 | muxscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#mux.: mux, |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // MatchRequest returns true if the request URL matches any pattern in mux. If no |
| 33 | // pattern is matched, false is returned. |
| 34 | func (m *Matcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#) MatchRequestscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#MatchRequest().(req *httpscip-go gomod github.com/golang/go/src go1.11 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.11 `net/http`/Request#) bool { |
| 35 | if _, pattern := m.muxscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#mux..Handlerscip-go gomod github.com/golang/go/src go1.11 `net/http`/ServeMux#Handler().(req); pattern != "" { |
| 36 | return true |
| 37 | } |
| 38 | |
| 39 | return false |
| 40 | } |
| 41 | |
| 42 | // MatchResponse returns true if the request URL associated with the response matches |
| 43 | // any pattern in mux. If pattern is matched, false is returned. |
| 44 | func (m *Matcherscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#) MatchResponsescip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#MatchResponse().(res *httpscip-go gomod github.com/golang/go/src go1.11 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.11 `net/http`/Response#) bool { |
| 45 | if _, pattern := m.muxscip-go gomod github.com/google/martian/v3 . `github.com/google/martian/v3/servemux`/Matcher#mux..Handlerscip-go gomod github.com/golang/go/src go1.11 `net/http`/ServeMux#Handler().(res.Requestscip-go gomod github.com/golang/go/src go1.11 `net/http`/Response#Request.); pattern != "" { |
| 46 | return true |
| 47 | } |
| 48 | |
| 49 | return false |
| 50 | } |