diff --git a/README.md b/README.md index f7944d3..a2aa614 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ Usage of apt-proxy: the host to bind to (default "0.0.0.0") -mirror string the mirror for fetching packages + -mode all + select the mode of system to cache: all / `ubuntu` / `debian` (default "all") -port string the port to bind to (default "3142") - -type string - select the type of system to cache: ubuntu/debian (default "ubuntu") ``` ## [WIP] Development @@ -106,13 +106,14 @@ go run apt-proxy.go # go test -cover ./... ? github.com/soulteary/apt-proxy [no test files] -ok github.com/soulteary/apt-proxy/cli 1.433s coverage: 69.2% of statements -ok github.com/soulteary/apt-proxy/linux 8.099s coverage: 80.2% of statements -ok github.com/soulteary/apt-proxy/pkgs/httpcache 2.357s coverage: 82.7% of statements +ok github.com/soulteary/apt-proxy/cli 0.852s coverage: 73.9% of statements +ok github.com/soulteary/apt-proxy/linux 7.465s coverage: 82.7% of statements +ok github.com/soulteary/apt-proxy/pkgs/httpcache (cached) coverage: 82.7% of statements ? github.com/soulteary/apt-proxy/pkgs/httplog [no test files] -ok github.com/soulteary/apt-proxy/pkgs/stream.v1 1.238s coverage: 100.0% of statements -ok github.com/soulteary/apt-proxy/pkgs/vfs 0.930s coverage: 59.3% of statements +ok github.com/soulteary/apt-proxy/pkgs/stream.v1 (cached) coverage: 100.0% of statements +ok github.com/soulteary/apt-proxy/pkgs/vfs (cached) coverage: 59.3% of statements ? github.com/soulteary/apt-proxy/proxy [no test files] +? github.com/soulteary/apt-proxy/state [no test files] ``` View coverage report: diff --git a/cli/cli.go b/cli/cli.go index c0117da..0f3838d 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -4,45 +4,57 @@ import ( "flag" "github.com/soulteary/apt-proxy/linux" + "github.com/soulteary/apt-proxy/state" ) const ( - DEFAULT_HOST = "0.0.0.0" - DEFAULT_PORT = "3142" - DEFAULT_CACHE_DIR = "./.aptcache" - DEFAULT_MIRROR = "" // "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/" - DEFAULT_TYPE = linux.LINUX_ALL_DISTROS - DEFAULT_DEBUG = false + DEFAULT_HOST = "0.0.0.0" + DEFAULT_PORT = "3142" + DEFAULT_CACHE_DIR = "./.aptcache" + DEFAULT_UBUNTU_MIRROR = "" // "https://mirrors.tuna.tsinghua.edu.cn/ubuntu/" + DEFAULT_DEBIAN_MIRROR = "" // "https://mirrors.tuna.tsinghua.edu.cn/debian/" + DEFAULT_MODE_NAME = linux.LINUX_ALL_DISTROS + DEFAULT_DEBUG = false ) var Version string -func getProxyMode(mode string) string { - if mode != linux.LINUX_ALL_DISTROS && - mode != linux.LINUX_DISTROS_DEBIAN && - mode != linux.LINUX_DISTROS_UBUNTU { - return linux.LINUX_ALL_DISTROS +func getProxyMode(mode string) int { + if mode == linux.LINUX_DISTROS_UBUNTU { + return linux.TYPE_LINUX_DISTROS_UBUNTU } - return mode + + if mode == linux.LINUX_DISTROS_DEBIAN { + return linux.TYPE_LINUX_DISTROS_DEBIAN + } + + return linux.TYPE_LINUX_ALL_DISTROS } func ParseFlags() (appFlags AppFlags) { var ( - host string - port string - mode string + host string + port string + userMode string ) flag.StringVar(&host, "host", DEFAULT_HOST, "the host to bind to") flag.StringVar(&port, "port", DEFAULT_PORT, "the port to bind to") - flag.StringVar(&mode, "mode", DEFAULT_TYPE, "select the mode of system to cache: `all` / `ubuntu` / `debian`") + flag.StringVar(&userMode, "mode", DEFAULT_MODE_NAME, "select the mode of system to cache: `all` / `ubuntu` / `debian`") flag.BoolVar(&appFlags.Debug, "debug", DEFAULT_DEBUG, "whether to output debugging logging") flag.StringVar(&appFlags.CacheDir, "cachedir", DEFAULT_CACHE_DIR, "the dir to store cache data in") - flag.StringVar(&appFlags.Mirror, "mirror", DEFAULT_MIRROR, "the mirror for fetching packages") + flag.StringVar(&appFlags.Ubuntu, "ubuntu", DEFAULT_UBUNTU_MIRROR, "the ubuntu mirror for fetching packages") + flag.StringVar(&appFlags.Debian, "debian", DEFAULT_DEBIAN_MIRROR, "the debian mirror for fetching packages") flag.Parse() - appFlags.Mode = getProxyMode(mode) + mode := getProxyMode(userMode) + + appFlags.Mode = mode appFlags.Listen = host + ":" + port appFlags.Version = Version + state.SetProxyMode(mode) + state.SetDebianMirror(appFlags.Debian) + state.SetUbuntuMirror(appFlags.Ubuntu) + return appFlags } diff --git a/cli/cli_test.go b/cli/cli_test.go index ae02316..adaf438 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -8,10 +8,15 @@ import ( ) func TestGetProxyMode(t *testing.T) { - if getProxyMode("not-support-os") != linux.LINUX_ALL_DISTROS { + if getProxyMode("not-support-os") != linux.TYPE_LINUX_ALL_DISTROS { t.Fatal("Incorrect return default value") } - if getProxyMode(linux.LINUX_DISTROS_DEBIAN) != linux.LINUX_DISTROS_DEBIAN { + + if getProxyMode(linux.LINUX_DISTROS_DEBIAN) != linux.TYPE_LINUX_DISTROS_DEBIAN { + t.Fatal("Incorrect return value") + } + + if getProxyMode(linux.LINUX_DISTROS_UBUNTU) != linux.TYPE_LINUX_DISTROS_UBUNTU { t.Fatal("Incorrect return value") } } @@ -28,12 +33,16 @@ func TestParseFlagsAndDaemonInit(t *testing.T) { t.Fatal("Default option `Listen` value mismatch") } - if flags.Mode != DEFAULT_TYPE { + if flags.Mode != getProxyMode(DEFAULT_MODE_NAME) { t.Fatal("Default option `Mode` value mismatch") } - if flags.Mirror != DEFAULT_MIRROR { - t.Fatal("Default option `Mirror` value mismatch") + if flags.Ubuntu != DEFAULT_UBUNTU_MIRROR { + t.Fatal("Default option `Ubuntu` value mismatch") + } + + if flags.Debian != DEFAULT_DEBIAN_MIRROR { + t.Fatal("Default option `Debian` value mismatch") } if flags.CacheDir != DEFAULT_CACHE_DIR { diff --git a/cli/daemon.go b/cli/daemon.go index f2cb825..6e037db 100644 --- a/cli/daemon.go +++ b/cli/daemon.go @@ -13,9 +13,12 @@ type AppFlags struct { Debug bool Version string CacheDir string - Mirror string - Mode string + Mode int Listen string + + // mirror + Ubuntu string + Debian string } func initStore(appFlags AppFlags) (cache httpcache.Cache, err error) { @@ -27,7 +30,8 @@ func initStore(appFlags AppFlags) (cache httpcache.Cache, err error) { } func initProxy(appFlags AppFlags, cache httpcache.Cache) (ap *proxy.AptProxy) { - ap = proxy.CreateAptProxyRouter(appFlags.Mirror, appFlags.Mode) + // TODO support both ubuntu and debian + ap = proxy.CreateAptProxyRouter() ap.Handler = httpcache.NewHandler(cache, ap.Handler) return ap } diff --git a/linux/benchmark_test.go b/linux/benchmark_test.go index 747eef4..07d85fd 100644 --- a/linux/benchmark_test.go +++ b/linux/benchmark_test.go @@ -14,7 +14,7 @@ func TestResourceBenchmark(t *testing.T) { } func TestMirrorsBenchmark(t *testing.T) { - mirrors := getGeoMirrorUrlsByMode(LINUX_DISTROS_UBUNTU) + mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) mirror, err := getTheFastestMirror(mirrors, UBUNTU_BENCHMAKR_URL) if err != nil { t.Fatal(err) diff --git a/linux/common.go b/linux/common.go index 9483a7f..ab9a8da 100644 --- a/linux/common.go +++ b/linux/common.go @@ -8,7 +8,14 @@ const ( LINUX_DISTROS_DEBIAN = "debian" ) +const ( + TYPE_LINUX_ALL_DISTROS int = 0 + TYPE_LINUX_DISTROS_UBUNTU = 1 + TYPE_LINUX_DISTROS_DEBIAN = 2 +) + type Rule struct { + OS int Pattern *regexp.Regexp CacheControl string Rewrite bool @@ -44,17 +51,17 @@ var DEBIAN_HOST_PATTERN = regexp.MustCompile( ) var DEBIAN_DEFAULT_CACHE_RULES = []Rule{ - {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true}, - {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true}, - {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, + {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, + {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, // Add file file hash - {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true}, + {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_DEBIAN}, } // Ubuntu @@ -91,15 +98,15 @@ var UBUNTU_HOST_PATTERN = regexp.MustCompile( ) var UBUNTU_DEFAULT_CACHE_RULES = []Rule{ - {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true}, - {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true}, - {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true}, - {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true}, + {Pattern: regexp.MustCompile(`deb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`udeb$`), CacheControl: `max-age=100000`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`DiffIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`PackagesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`Packages\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`SourcesIndex$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`Sources\.(bz2|gz|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`Release(\.gpg)?$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, + {Pattern: regexp.MustCompile(`Translation-(en|fr)\.(gz|bz2|bzip2|lzma)$`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, // Add file file hash - {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true}, + {Pattern: regexp.MustCompile(`/by-hash/`), CacheControl: `max-age=3600`, Rewrite: true, OS: TYPE_LINUX_DISTROS_UBUNTU}, } diff --git a/linux/mirrors.go b/linux/mirrors.go index f95155a..e758da9 100644 --- a/linux/mirrors.go +++ b/linux/mirrors.go @@ -6,8 +6,8 @@ import ( "regexp" ) -func getGeoMirrorUrlsByMode(mode string) (mirrors []string) { - if mode == LINUX_DISTROS_UBUNTU { +func getGeoMirrorUrlsByMode(mode int) (mirrors []string) { + if mode == TYPE_LINUX_DISTROS_UBUNTU { ubuntuMirrorsOnline, err := getUbuntuMirrorUrlsByGeo() if err != nil { return BUILDIN_UBUNTU_MIRRORS @@ -15,7 +15,7 @@ func getGeoMirrorUrlsByMode(mode string) (mirrors []string) { return ubuntuMirrorsOnline } - if mode == LINUX_DISTROS_DEBIAN { + if mode == TYPE_LINUX_DISTROS_DEBIAN { return BUILDIN_DEBIAN_MIRRORS } @@ -40,8 +40,8 @@ func getUbuntuMirrorUrlsByGeo() (mirrors []string, err error) { return mirrors, scanner.Err() } -func getPredefinedConfiguration(osType string) (string, *regexp.Regexp) { - if osType == LINUX_DISTROS_UBUNTU { +func getPredefinedConfiguration(proxyMode int) (string, *regexp.Regexp) { + if proxyMode == TYPE_LINUX_DISTROS_UBUNTU { return UBUNTU_BENCHMAKR_URL, UBUNTU_HOST_PATTERN } else { return DEBIAN_BENCHMAKR_URL, DEBIAN_HOST_PATTERN diff --git a/linux/mirrors_test.go b/linux/mirrors_test.go index 1b9eb6d..60064f9 100644 --- a/linux/mirrors_test.go +++ b/linux/mirrors_test.go @@ -16,24 +16,24 @@ func TestGetGeoMirrors(t *testing.T) { } func TestGetMirrorUrlsByGeo(t *testing.T) { - mirrors := getGeoMirrorUrlsByMode(LINUX_ALL_DISTROS) + mirrors := getGeoMirrorUrlsByMode(TYPE_LINUX_ALL_DISTROS) if len(mirrors) == 0 { t.Fatal("No mirrors found") } - mirrors = getGeoMirrorUrlsByMode(LINUX_DISTROS_DEBIAN) + mirrors = getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_DEBIAN) if len(mirrors) != len(BUILDIN_DEBIAN_MIRRORS) { t.Fatal("Get mirrors error") } - mirrors = getGeoMirrorUrlsByMode(LINUX_DISTROS_UBUNTU) + mirrors = getGeoMirrorUrlsByMode(TYPE_LINUX_DISTROS_UBUNTU) if len(mirrors) == 0 { t.Fatal("No mirrors found") } } func TestGetPredefinedConfiguration(t *testing.T) { - res, pattern := getPredefinedConfiguration(LINUX_DISTROS_UBUNTU) + res, pattern := getPredefinedConfiguration(TYPE_LINUX_DISTROS_UBUNTU) if res != UBUNTU_BENCHMAKR_URL { t.Fatal("Failed to get resource link") } @@ -41,7 +41,7 @@ func TestGetPredefinedConfiguration(t *testing.T) { t.Fatal("Failed to verify domain name rules") } - res, pattern = getPredefinedConfiguration(LINUX_DISTROS_DEBIAN) + res, pattern = getPredefinedConfiguration(TYPE_LINUX_DISTROS_DEBIAN) if res != DEBIAN_BENCHMAKR_URL { t.Fatal("Failed to get resource link") } diff --git a/linux/rewriter.go b/linux/rewriter.go index e064612..22bde1c 100644 --- a/linux/rewriter.go +++ b/linux/rewriter.go @@ -13,25 +13,38 @@ type URLRewriter struct { pattern *regexp.Regexp } -func NewRewriter(mirrorUrl string, osType string) *URLRewriter { +func GetRewriteRulesByMode(mode int) (rules []Rule) { + if mode == TYPE_LINUX_DISTROS_UBUNTU { + return UBUNTU_DEFAULT_CACHE_RULES + } + if mode == TYPE_LINUX_DISTROS_DEBIAN { + return DEBIAN_DEFAULT_CACHE_RULES + } + + rules = append(rules, UBUNTU_DEFAULT_CACHE_RULES...) + rules = append(rules, DEBIAN_DEFAULT_CACHE_RULES...) + return rules +} + +func NewRewriter(mirrorUrl string, proxyMode int) *URLRewriter { u := &URLRewriter{} // user specify mirror - // TODO Both systems are supported + // TODO support both ubuntu and debian if len(mirrorUrl) > 0 { mirror, err := url.Parse(mirrorUrl) if err == nil { log.Printf("using specify mirror %s", mirrorUrl) u.mirror = mirror - _, pattern := getPredefinedConfiguration(osType) + _, pattern := getPredefinedConfiguration(proxyMode) u.pattern = pattern return u } } - benchmarkUrl, pattern := getPredefinedConfiguration(osType) + benchmarkUrl, pattern := getPredefinedConfiguration(proxyMode) u.pattern = pattern - mirrors := getGeoMirrorUrlsByMode(osType) + mirrors := getGeoMirrorUrlsByMode(proxyMode) mirrorUrl, err := getTheFastestMirror(mirrors, benchmarkUrl) if err != nil { log.Println("Error finding fastest mirror", err) diff --git a/linux/rewriter_test.go b/linux/rewriter_test.go index bef72dc..2314f84 100644 --- a/linux/rewriter_test.go +++ b/linux/rewriter_test.go @@ -7,7 +7,7 @@ import ( ) func TestNewRewriter(t *testing.T) { - ap := *NewRewriter("", LINUX_DISTROS_UBUNTU) + ap := *NewRewriter("", TYPE_LINUX_DISTROS_UBUNTU) time.Sleep((BENCHMARK_DETECT_TIMEOUT + 1) * time.Second) @@ -20,7 +20,7 @@ func TestNewRewriter(t *testing.T) { } func TestNewRewriterWithSpecifyMirror(t *testing.T) { - ap := *NewRewriter("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/", LINUX_DISTROS_UBUNTU) + ap := *NewRewriter("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/", TYPE_LINUX_DISTROS_UBUNTU) if ap.mirror.Host != "mirrors.tuna.tsinghua.edu.cn" { t.Fatal("Mirror host incorrect") } @@ -42,3 +42,20 @@ func TestRuleToString(t *testing.T) { t.Fatal("test rules toString faild") } } + +func TestGetRewriteRulesByMode(t *testing.T) { + rules := GetRewriteRulesByMode(TYPE_LINUX_DISTROS_UBUNTU) + if rules[0].Pattern != UBUNTU_DEFAULT_CACHE_RULES[0].Pattern { + t.Fatal("Pattern Not Match") + } + + rules = GetRewriteRulesByMode(TYPE_LINUX_DISTROS_DEBIAN) + if rules[0].Pattern != DEBIAN_DEFAULT_CACHE_RULES[0].Pattern { + t.Fatal("Pattern Not Match") + } + + rules = GetRewriteRulesByMode(TYPE_LINUX_ALL_DISTROS) + if len(rules) != (len(DEBIAN_DEFAULT_CACHE_RULES) + len(UBUNTU_DEFAULT_CACHE_RULES)) { + t.Fatal("Pattern Length Not Match") + } +} diff --git a/proxy/proxy.go b/proxy/proxy.go index ef94ed6..5364f57 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -7,6 +7,7 @@ import ( "time" "github.com/soulteary/apt-proxy/linux" + "github.com/soulteary/apt-proxy/state" ) var rewriter *linux.URLRewriter @@ -22,17 +23,19 @@ type AptProxy struct { Rules []linux.Rule } -func CreateAptProxyRouter(mirror string, osType string) *AptProxy { - rewriter = linux.NewRewriter(mirror, osType) - var rules []linux.Rule - if osType == linux.LINUX_DISTROS_UBUNTU { - rules = linux.UBUNTU_DEFAULT_CACHE_RULES - } else if osType == linux.LINUX_DISTROS_DEBIAN { - rules = linux.DEBIAN_DEFAULT_CACHE_RULES - } +func init() { + +} + +func CreateAptProxyRouter() *AptProxy { + mirror := state.DEBIAN_MIRROR + + // TODO support both ubuntu and debian + proxyMode := state.GetProxyMode() + rewriter = linux.NewRewriter(mirror, proxyMode) return &AptProxy{ - Rules: rules, + Rules: linux.GetRewriteRulesByMode(proxyMode), Handler: &httputil.ReverseProxy{ Director: func(r *http.Request) {}, Transport: defaultTransport, diff --git a/state/state.go b/state/state.go new file mode 100644 index 0000000..8b4fdd0 --- /dev/null +++ b/state/state.go @@ -0,0 +1,29 @@ +package state + +var UBUNTU_MIRROR = "" +var DEBIAN_MIRROR = "" +var PROXY_MODE = 0 + +func SetProxyMode(mode int) { + PROXY_MODE = mode +} + +func GetProxyMode() int { + return PROXY_MODE +} + +func SetUbuntuMirror(mirror string) { + UBUNTU_MIRROR = mirror +} + +func GetUbuntuMirror() string { + return UBUNTU_MIRROR +} + +func SetDebianMirror(mirror string) { + DEBIAN_MIRROR = mirror +} + +func GetDebianMirror() string { + return DEBIAN_MIRROR +}