forked from lox/apt-proxy
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split state to independent files
- Loading branch information
Showing
13 changed files
with
290 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package state | ||
|
||
import ( | ||
"net/url" | ||
|
||
Define "github.com/soulteary/apt-proxy/internal/define" | ||
Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" | ||
) | ||
|
||
var ALPINE_MIRROR *url.URL | ||
|
||
func SetAlpineMirror(input string) { | ||
if input == "" { | ||
CENTOS_MIRROR = nil | ||
return | ||
} | ||
|
||
mirror := input | ||
alias := Mirrors.GetMirrorURLByAliases(Define.TYPE_LINUX_DISTROS_ALPINE, input) | ||
if alias != "" { | ||
mirror = alias | ||
} | ||
|
||
url, err := url.Parse(mirror) | ||
if err != nil { | ||
ALPINE_MIRROR = nil | ||
return | ||
} | ||
CENTOS_MIRROR = url | ||
} | ||
|
||
func GetAlpineMirror() *url.URL { | ||
return CENTOS_MIRROR | ||
} | ||
|
||
func ResetAlpineMirror() { | ||
CENTOS_MIRROR = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package state_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
State "github.com/soulteary/apt-proxy/internal/state" | ||
) | ||
|
||
func TestGetAndSetAlpineMirror(t *testing.T) { | ||
State.SetAlpineMirror("https://mirrors.tuna.tsinghua.edu.cn/alpine/") | ||
mirror := State.GetAlpineMirror() | ||
if !strings.Contains(strings.ToLower(mirror.Path), "alpine") { | ||
t.Fatal("Test Set/Get Alpine Mirror Value Faild") | ||
} | ||
|
||
State.SetAlpineMirror("") | ||
mirror = State.GetAlpineMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Set/Get Alpine Mirror to Null Faild") | ||
} | ||
|
||
State.ResetAlpineMirror() | ||
mirror = State.GetAlpineMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Clear Alpine Mirror Faild") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package state | ||
|
||
import ( | ||
"net/url" | ||
|
||
Define "github.com/soulteary/apt-proxy/internal/define" | ||
Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" | ||
) | ||
|
||
var CENTOS_MIRROR *url.URL | ||
|
||
func SetCentOSMirror(input string) { | ||
if input == "" { | ||
CENTOS_MIRROR = nil | ||
return | ||
} | ||
|
||
mirror := input | ||
alias := Mirrors.GetMirrorURLByAliases(Define.TYPE_LINUX_DISTROS_CENTOS, input) | ||
if alias != "" { | ||
mirror = alias | ||
} | ||
|
||
url, err := url.Parse(mirror) | ||
if err != nil { | ||
CENTOS_MIRROR = nil | ||
return | ||
} | ||
CENTOS_MIRROR = url | ||
} | ||
|
||
func GetCentOSMirror() *url.URL { | ||
return CENTOS_MIRROR | ||
} | ||
|
||
func ResetCentOSMirror() { | ||
CENTOS_MIRROR = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package state_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
State "github.com/soulteary/apt-proxy/internal/state" | ||
) | ||
|
||
func TestGetAndSetCentOSMirror(t *testing.T) { | ||
State.SetCentOSMirror("https://mirrors.tuna.tsinghua.edu.cn/centos/") | ||
mirror := State.GetCentOSMirror() | ||
if !strings.Contains(strings.ToLower(mirror.Path), "centos") { | ||
t.Fatal("Test Set/Get CentOS Mirror Value Faild") | ||
} | ||
|
||
State.SetCentOSMirror("") | ||
mirror = State.GetCentOSMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Set/Get CentOS Mirror to Null Faild") | ||
} | ||
|
||
State.ResetCentOSMirror() | ||
mirror = State.GetCentOSMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Clear CentOS Mirror Faild") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package state | ||
|
||
import ( | ||
"net/url" | ||
|
||
Define "github.com/soulteary/apt-proxy/internal/define" | ||
Mirrors "github.com/soulteary/apt-proxy/internal/mirrors" | ||
) | ||
|
||
var DEBIAN_MIRROR *url.URL | ||
|
||
func SetDebianMirror(input string) { | ||
if input == "" { | ||
DEBIAN_MIRROR = nil | ||
return | ||
} | ||
|
||
mirror := input | ||
alias := Mirrors.GetMirrorURLByAliases(Define.TYPE_LINUX_DISTROS_DEBIAN, input) | ||
if alias != "" { | ||
mirror = alias | ||
} | ||
|
||
url, err := url.Parse(mirror) | ||
if err != nil { | ||
DEBIAN_MIRROR = nil | ||
return | ||
} | ||
DEBIAN_MIRROR = url | ||
} | ||
|
||
func GetDebianMirror() *url.URL { | ||
return DEBIAN_MIRROR | ||
} | ||
|
||
func ResetDebianMirror() { | ||
DEBIAN_MIRROR = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package state_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
State "github.com/soulteary/apt-proxy/internal/state" | ||
) | ||
|
||
func TestGetAndSetDebianMirror(t *testing.T) { | ||
State.SetDebianMirror("https://mirrors.tuna.tsinghua.edu.cn/debian/") | ||
mirror := State.GetDebianMirror() | ||
if !strings.Contains(mirror.Path, "debian") { | ||
t.Fatal("Test Set/Get Debian Mirror Value Faild") | ||
} | ||
|
||
State.SetDebianMirror("") | ||
mirror = State.GetDebianMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Set/Get Debian Mirror to Null Faild") | ||
} | ||
|
||
State.ResetDebianMirror() | ||
mirror = State.GetDebianMirror() | ||
if mirror != nil { | ||
t.Fatal("Test Clear Debian Mirror Faild") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package state | ||
|
||
var PROXY_MODE = 0 | ||
|
||
func SetProxyMode(mode int) { | ||
PROXY_MODE = mode | ||
} | ||
|
||
func GetProxyMode() int { | ||
return PROXY_MODE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package state | ||
|
||
import ( | ||
"testing" | ||
|
||
Define "github.com/soulteary/apt-proxy/internal/define" | ||
) | ||
|
||
func TestSetProxyMode(t *testing.T) { | ||
SetProxyMode(Define.TYPE_LINUX_ALL_DISTROS) | ||
if GetProxyMode() != Define.TYPE_LINUX_ALL_DISTROS { | ||
t.Fatal("Test Set/Get ProxyMode Faild") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.