refactor interceptor invocation
This commit is contained in:
1 parent
03fa95fcb5
commit
f025b6ea36
1 file changed
+5
-7
+5
-7
@@ -84,19 +84,17 @@ func NewProxy(c Config) (*Proxy, error) {
|
|||||||
func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
Info.Printf("%s %s", r.Method, r.URL)
|
Info.Printf("%s %s", r.Method, r.URL)
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
|
var i interceptor
|
||||||
switch {
|
switch {
|
||||||
case containerCreateRegexp.MatchString(path):
|
case containerCreateRegexp.MatchString(path):
|
||||||
proxy.serveWithInterceptor(&createContainerInterceptor{proxy.client, proxy.dockerBridgeIP, proxy.WithDNS, proxy.WithIPAM}, w, r)
|
i = &createContainerInterceptor{proxy.client, proxy.dockerBridgeIP, proxy.WithDNS, proxy.WithIPAM}
|
||||||
case containerStartRegexp.MatchString(path):
|
case containerStartRegexp.MatchString(path):
|
||||||
proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.WithDNS, proxy.WithIPAM}, w, r)
|
i = &startContainerInterceptor{proxy.client, proxy.WithDNS, proxy.WithIPAM}
|
||||||
case execCreateRegexp.MatchString(path):
|
case execCreateRegexp.MatchString(path):
|
||||||
proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.WithIPAM}, w, r)
|
i = &createExecInterceptor{proxy.client, proxy.WithIPAM}
|
||||||
default:
|
default:
|
||||||
proxy.serveWithInterceptor(&nullInterceptor{}, w, r)
|
i = &nullInterceptor{}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *Proxy) serveWithInterceptor(i interceptor, w http.ResponseWriter, r *http.Request) {
|
|
||||||
newClient(proxy.dial, i).ServeHTTP(w, r)
|
newClient(proxy.dial, i).ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user