Skip to content

Commit

Permalink
chore: refactor state
Browse files Browse the repository at this point in the history
  • Loading branch information
soulteary committed Nov 17, 2022
1 parent 7f3ad1f commit 7003051
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"

Mirrors "github.com/soulteary/apt-proxy/internal/mirrors"
"github.com/soulteary/apt-proxy/state"
State "github.com/soulteary/apt-proxy/internal/state"
)

const (
Expand Down Expand Up @@ -52,9 +52,9 @@ func ParseFlags() (appFlags AppFlags) {
appFlags.Listen = host + ":" + port
appFlags.Version = Version

state.SetProxyMode(mode)
state.SetDebianMirror(appFlags.Debian)
state.SetUbuntuMirror(appFlags.Ubuntu)
State.SetProxyMode(mode)
State.SetDebianMirror(appFlags.Debian)
State.SetUbuntuMirror(appFlags.Ubuntu)

return appFlags
}
6 changes: 3 additions & 3 deletions internal/rewriter/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

Benchmark "github.com/soulteary/apt-proxy/internal/benchmark"
Mirrors "github.com/soulteary/apt-proxy/internal/mirrors"
"github.com/soulteary/apt-proxy/state"
State "github.com/soulteary/apt-proxy/internal/state"
)

type URLRewriters struct {
Expand Down Expand Up @@ -36,7 +36,7 @@ func GetRewriteRulesByMode(mode int) (rules []Mirrors.Rule) {

func getRewriterForDebian() *URLRewriter {
u := &URLRewriter{}
debianMirror := state.GetDebianMirror()
debianMirror := State.GetDebianMirror()
benchmarkUrl, pattern := Mirrors.GetPredefinedConfiguration(Mirrors.TYPE_LINUX_DISTROS_DEBIAN)
u.pattern = pattern

Expand All @@ -62,7 +62,7 @@ func getRewriterForDebian() *URLRewriter {

func getRewriterForUbuntu() *URLRewriter {
u := &URLRewriter{}
ubuntuMirror := state.GetUbuntuMirror()
ubuntuMirror := State.GetUbuntuMirror()
benchmarkUrl, pattern := Mirrors.GetPredefinedConfiguration(Mirrors.TYPE_LINUX_DISTROS_UBUNTU)
u.pattern = pattern

Expand Down
6 changes: 3 additions & 3 deletions internal/rewriter/rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

Benchmark "github.com/soulteary/apt-proxy/internal/benchmark"
Mirrors "github.com/soulteary/apt-proxy/internal/mirrors"
"github.com/soulteary/apt-proxy/state"
State "github.com/soulteary/apt-proxy/internal/state"
)

func TestGetRewriteRulesByMode(t *testing.T) {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestCreateNewRewritersForAll(t *testing.T) {
}

func TestCreateNewRewritersWithSpecifyMirror(t *testing.T) {
state.SetUbuntuMirror("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/")
State.SetUbuntuMirror("https://mirrors.tuna.tsinghua.edu.cn/ubuntu/")

ap := *CreateNewRewriters(Mirrors.TYPE_LINUX_DISTROS_UBUNTU)
if ap.ubuntu.mirror.Host != "mirrors.tuna.tsinghua.edu.cn" {
Expand All @@ -92,7 +92,7 @@ func TestCreateNewRewritersWithSpecifyMirror(t *testing.T) {
t.Fatal("mirror path incorrect")
}

state.ResetUbuntuMirror()
State.ResetUbuntuMirror()
}

func TestMatchingRule(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/server/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

Mirrors "github.com/soulteary/apt-proxy/internal/mirrors"
Rewriter "github.com/soulteary/apt-proxy/internal/rewriter"
"github.com/soulteary/apt-proxy/state"
State "github.com/soulteary/apt-proxy/internal/state"
)

var rewriter *Rewriter.URLRewriters
Expand All @@ -25,7 +25,7 @@ type AptProxy struct {
}

func CreateAptProxyRouter() *AptProxy {
mode := state.GetProxyMode()
mode := State.GetProxyMode()
rewriter = Rewriter.CreateNewRewriters(mode)

return &AptProxy{
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7003051

Please sign in to comment.