From 612d77eaab2322e492b93b924d40727ba8b333b1 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 29 Jan 2015 22:08:40 -0700 Subject: [PATCH] Moved Path type around --- middleware/headers/headers.go | 4 ++-- middleware/middleware.go | 15 +-------------- middleware/path.go | 13 +++++++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 middleware/path.go diff --git a/middleware/headers/headers.go b/middleware/headers/headers.go index edac2f22..dec6d83c 100644 --- a/middleware/headers/headers.go +++ b/middleware/headers/headers.go @@ -3,7 +3,7 @@ package headers import ( "net/http" - "github.com/mholt/caddy/middleware/util" + "github.com/mholt/caddy/middleware" ) // Headers is middleware that adds headers to the responses @@ -17,7 +17,7 @@ type Headers struct { // adding headers to the response according to the configured rules. func (h *Headers) ServeHTTP(w http.ResponseWriter, r *http.Request) { for _, rule := range h.rules { - if util.Path(r.URL.Path).Matches(rule.Url) { + if middleware.Path(r.URL.Path).Matches(rule.Url) { for _, header := range rule.Headers { w.Header().Set(header.Name, header.Value) } diff --git a/middleware/middleware.go b/middleware/middleware.go index aadc491d..d0b4d1e1 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -2,10 +2,7 @@ // the servers to use, according to their configuration. package middleware -import ( - "net/http" - "strings" -) +import "net/http" type ( // Generator represents the outer layer of a middleware that @@ -35,13 +32,3 @@ type ( Port() string } ) - -// Path represents a URI path, maybe with pattern characters. -type Path string - -// Path matching will probably not always be a direct -// comparison; this method assures that paths can be -// easily matched. -func (p Path) Matches(other string) bool { - return strings.HasPrefix(string(p), other) -} diff --git a/middleware/path.go b/middleware/path.go new file mode 100644 index 00000000..4ddc6f9d --- /dev/null +++ b/middleware/path.go @@ -0,0 +1,13 @@ +package middleware + +import "strings" + +// Path represents a URI path, maybe with pattern characters. +type Path string + +// Path matching will probably not always be a direct +// comparison; this method assures that paths can be +// easily matched. +func (p Path) Matches(other string) bool { + return strings.HasPrefix(string(p), other) +}