From a860975f5348f8957a2a5b9e99d9772ec523ce7a Mon Sep 17 00:00:00 2001 From: Imran Ismail Date: Wed, 25 Nov 2020 12:22:20 +0800 Subject: [PATCH] chore: rename custom url modifier, filter and verifier --- bffurl/url_filter.go | 6 +++--- bffurl/url_modifier.go | 11 +++++++---- bffurl/url_verifier.go | 11 +++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/bffurl/url_filter.go b/bffurl/url_filter.go index 1021718..91ce525 100644 --- a/bffurl/url_filter.go +++ b/bffurl/url_filter.go @@ -24,10 +24,10 @@ import ( "github.com/google/martian/v3/parse" ) -var noop = martian.Noop("bffurl.Filter") +var noop = martian.Noop("bff.URLFilter") func init() { - parse.Register("bffurl.Filter", filterFromJSON) + parse.Register("bff.URLFilter", filterFromJSON) } // Filter runs modifiers iff the request URL matches all of the segments in url. @@ -48,7 +48,7 @@ type filterJSON struct { // NewFilter constructs a filter that applies the modifer when the // request URL matches all of the provided URL segments. func NewFilter(u *url.URL) *Filter { - log.Debugf("bffurl.NewFilter: %s", u) + log.Debugf("bff.NewURLFilter: %s", u) m := NewMatcher(u) f := filter.New() diff --git a/bffurl/url_modifier.go b/bffurl/url_modifier.go index d68ff16..c7a3480 100644 --- a/bffurl/url_modifier.go +++ b/bffurl/url_modifier.go @@ -22,6 +22,7 @@ import ( "net/url" "github.com/google/martian/v3" + "github.com/google/martian/v3/log" "github.com/google/martian/v3/parse" ) @@ -42,7 +43,7 @@ type modifierJSON struct { } func init() { - parse.Register("bffurl.Modifier", modifierFromJSON) + parse.Register("bff.URLModifier", modifierFromJSON) } // ModifyRequest sets the fields of req.URL to m.Url if they are not the zero value. @@ -68,10 +69,12 @@ func (m *Modifier) ModifyRequest(req *http.Request) error { } // NewModifier overrides the url of the request. -func NewModifier(url *url.URL) martian.RequestModifier { +func NewModifier(u *url.URL) martian.RequestModifier { + log.Debugf("bff.NewURLModifier: %s", u) + return &Modifier{ - url: url, - pattern: NewPattern(url.Path), + url: u, + pattern: NewPattern(u.Path), } } diff --git a/bffurl/url_verifier.go b/bffurl/url_verifier.go index 4f8000e..08598a2 100644 --- a/bffurl/url_verifier.go +++ b/bffurl/url_verifier.go @@ -22,6 +22,7 @@ import ( "strings" "github.com/google/martian/v3" + "github.com/google/martian/v3/log" "github.com/google/martian/v3/martianurl" "github.com/google/martian/v3/parse" "github.com/google/martian/v3/verify" @@ -33,7 +34,7 @@ const ( ) func init() { - parse.Register("bffurl.Verifier", verifierFromJSON) + parse.Register("bff.URLVerifier", verifierFromJSON) } // Verifier verifies the structure of URLs. @@ -52,11 +53,13 @@ type verifierJSON struct { } // NewVerifier returns a new URL verifier. -func NewVerifier(url *url.URL) verify.RequestVerifier { +func NewVerifier(u *url.URL) verify.RequestVerifier { + log.Debugf("bff.NewURLVerifier: %s", u) + return &Verifier{ - url: url, + url: u, err: martian.NewMultiError(), - pattern: NewPattern(url.Path), + pattern: NewPattern(u.Path), } }