From 633df0cdafb5ac3930e8bd34c2035a7470be04d7 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 4 Sep 2015 13:35:14 +0100 Subject: [PATCH] refactor: extract docker API endpoint regexp creation --- proxy/proxy.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 0d91fe9e..f9a64076 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -24,16 +24,20 @@ const ( ) var ( - containerCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/create$") - containerStartRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/(re)?start$") - containerInspectRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/json$") - execCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/exec$") - execInspectRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/exec/[^/]*/json$") + containerCreateRegexp = dockerAPIEndpoint("containers/create") + containerStartRegexp = dockerAPIEndpoint("containers/[^/]*/(re)?start") + containerInspectRegexp = dockerAPIEndpoint("containers/[^/]*/json") + execCreateRegexp = dockerAPIEndpoint("containers/[^/]*/exec") + execInspectRegexp = dockerAPIEndpoint("exec/[^/]*/json") ErrWeaveCIDRNone = errors.New("the container was created with the '-e WEAVE_CIDR=none' option") ErrNoDefaultIPAM = errors.New("the container was created without specifying an IP address with '-e WEAVE_CIDR=...' and the proxy was started with the '--no-default-ipalloc' option") ) +func dockerAPIEndpoint(endpoint string) *regexp.Regexp { + return regexp.MustCompile("^(/v[0-9\\.]*)?/" + endpoint + "$") +} + type Config struct { HostnameMatch string HostnameReplacement string