mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-07 08:57:07 +00:00
refactor(handler): extract path matcher for reuse
This commit is contained in:
@@ -126,12 +126,7 @@ func (s *Standalone) GetIngresses() *ingress.Ingresses {
|
||||
}
|
||||
|
||||
func (s *Standalone) GetPath(r *http.Request) string {
|
||||
path, ok := mw.PathFrom(r.Context())
|
||||
if !ok {
|
||||
path = s.Ingresses.MatchingPath(r)
|
||||
}
|
||||
|
||||
return path
|
||||
return GetPath(r, s)
|
||||
}
|
||||
|
||||
func (s *Standalone) GetRedirect() url.Redirect {
|
||||
|
||||
23
pkg/handler/path.go
Normal file
23
pkg/handler/path.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/nais/wonderwall/pkg/ingress"
|
||||
mw "github.com/nais/wonderwall/pkg/middleware"
|
||||
)
|
||||
|
||||
type PathSource interface {
|
||||
GetIngresses() *ingress.Ingresses
|
||||
}
|
||||
|
||||
// GetPath returns the matching context path from the list of registered ingresses.
|
||||
// If none match, an empty string is returned.
|
||||
func GetPath(r *http.Request, src PathSource) string {
|
||||
path, ok := mw.PathFrom(r.Context())
|
||||
if !ok {
|
||||
path = src.GetIngresses().MatchingPath(r)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
Reference in New Issue
Block a user