update matcher to path matcher
This commit is contained in:
parent
e14bcb205b
commit
85968bb5cf
10
config.go
10
config.go
@ -10,27 +10,27 @@ type UpstreamPriorityGroup struct {
|
||||
Priority int `yaml:"priority"`
|
||||
}
|
||||
|
||||
type UpstreamMatch struct {
|
||||
type PathTransformation struct {
|
||||
Match string `yaml:"match"`
|
||||
Replace string `yaml:"replace"`
|
||||
}
|
||||
|
||||
type Upstream struct {
|
||||
Server string `yaml:"server"`
|
||||
Match UpstreamMatch `yaml:"match"`
|
||||
Path PathTransformation `yaml:"path"`
|
||||
AllowedRedirect *string `yaml:"allowed-redirect"`
|
||||
PriorityGroups []UpstreamPriorityGroup `yaml:"priority-groups"`
|
||||
}
|
||||
|
||||
func (upstream Upstream) GetPath(orig string) (string, bool, error) {
|
||||
if upstream.Match.Match == "" || upstream.Match.Replace == "" {
|
||||
if upstream.Path.Match == "" || upstream.Path.Replace == "" {
|
||||
return orig, true, nil
|
||||
}
|
||||
matcher, err := regexp.Compile(upstream.Match.Match)
|
||||
matcher, err := regexp.Compile(upstream.Path.Match)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
return matcher.ReplaceAllString(orig, upstream.Match.Replace), matcher.MatchString(orig), nil
|
||||
return matcher.ReplaceAllString(orig, upstream.Path.Replace), matcher.MatchString(orig), nil
|
||||
}
|
||||
|
||||
type LocalStorage struct {
|
||||
|
52
config.yaml
52
config.yaml
@ -1,91 +1,99 @@
|
||||
upstream:
|
||||
- server: https://mirrors.aliyun.com
|
||||
match:
|
||||
match: /(debian|ubuntu|ubuntu-releases|alpine|archlinux|kali|manjaro|msys2|almalinux|rocky|centos|centos-stream|centos-vault|fedora|epel|gnu|pypi)/(.*)
|
||||
path:
|
||||
match: /(debian|ubuntu|ubuntu-ports|ubuntu-releases|alpine|archlinux|kali|manjaro|msys2|almalinux|rocky|centos|centos-stream|centos-vault|fedora|epel|gnu|pypi)/(.*)
|
||||
replace: '/$1/$2'
|
||||
- server: https://mirrors.tencent.com
|
||||
match:
|
||||
match: /(debian|ubuntu|ubuntu-releases|alpine|archlinux|kali|manjaro|msys2|almalinux|rocky|centos|centos-stream|centos-vault|fedora|epel|gnu)/(.*)
|
||||
path:
|
||||
match: /(debian|ubuntu|ubuntu-ports|ubuntu-releases|alpine|archlinux|kali|manjaro|msys2|almalinux|rocky|centos|centos-stream|centos-vault|fedora|epel|gnu)/(.*)
|
||||
replace: '/$1/$2'
|
||||
- server: https://mirrors.ustc.edu.cn
|
||||
match:
|
||||
path:
|
||||
match: /(debian|ubuntu|ubuntu-releases|alpine|archlinux|kali|manjaro|msys2|almalinux|rocky|centos|centos-stream|centos-vault|fedora|epel|elrepo|remi|rpmfusion|tailscale|gnu|rust-static|pypi)/(.*)
|
||||
replace: '/$1/$2'
|
||||
- server: https://packages.microsoft.com/repos/code
|
||||
match:
|
||||
path:
|
||||
match: /microsoft-code(.*)
|
||||
replace: '$1'
|
||||
- server: https://archive.ubuntu.com
|
||||
match:
|
||||
path:
|
||||
match: /ubuntu/(.*)
|
||||
replace: /$1
|
||||
- server: https://ports.ubuntu.com
|
||||
path:
|
||||
match: /ubuntu-ports/(.*)
|
||||
replace: /$1
|
||||
# priority-groups:
|
||||
# - match: /dists/.*
|
||||
# priority: 10
|
||||
- server: https://releases.ubuntu.com/
|
||||
match:
|
||||
path:
|
||||
match: /ubuntu-releases/(.*)
|
||||
replace: /$1
|
||||
- server: https://apt.releases.hashicorp.com
|
||||
match:
|
||||
path:
|
||||
match: /hashicorp-deb/(.*)
|
||||
replace: /$1
|
||||
- server: https://rpm.releases.hashicorp.com
|
||||
match:
|
||||
path:
|
||||
match: /hashicorp-rpm/(.*)
|
||||
replace: /$1
|
||||
- server: https://dl.google.com/linux/chrome
|
||||
match:
|
||||
path:
|
||||
match: /google-chrome/(.*)
|
||||
replace: /$1
|
||||
- server: https://pkgs.tailscale.com/stable
|
||||
match:
|
||||
path:
|
||||
match: /tailscale/(.*)
|
||||
replace: /$1
|
||||
- server: http://update.cs2c.com.cn:8080
|
||||
match:
|
||||
path:
|
||||
match: /kylinlinux/(.*)
|
||||
replace: /$1
|
||||
- server: https://cdn.jsdelivr.net
|
||||
match:
|
||||
path:
|
||||
match: /jsdelivr/(.*)
|
||||
replace: /$1
|
||||
- server: https://dl-cdn.alpinelinux.org
|
||||
match:
|
||||
path:
|
||||
match: /alpine/(.*)
|
||||
replace: /$1
|
||||
- server: https://repo.almalinux.org
|
||||
match:
|
||||
path:
|
||||
match: /almalinux/(.*)
|
||||
replace: /almalinux/$1
|
||||
- server: https://dl.rockylinux.org/pub/rocky
|
||||
match:
|
||||
path:
|
||||
match: /rocky/(.*)
|
||||
replace: /$1
|
||||
- server: https://dl.fedoraproject.org/pub/epel
|
||||
match:
|
||||
path:
|
||||
match: /epel/(.*)
|
||||
replace: /$1
|
||||
- server: https://deb.debian.org
|
||||
match:
|
||||
path:
|
||||
match: /(debian|debian-security)/(.*)
|
||||
replace: /$1/$2
|
||||
# priority-groups:
|
||||
# - match: /dists/.*
|
||||
# priority: 10
|
||||
- server: https://static.rust-lang.org
|
||||
match:
|
||||
path:
|
||||
match: /rust-static/(.*)
|
||||
replace: /$1
|
||||
- server: https://storage.flutter-io.cn
|
||||
match:
|
||||
path:
|
||||
match: /flutter-storage/(.*)
|
||||
replace: /$1
|
||||
- server: https://cdn-mirror.chaotic.cx/chaotic-aur
|
||||
match:
|
||||
path:
|
||||
match: /chaotic-aur/(.*)
|
||||
replace: /$1
|
||||
allowed-redirect: "^https?://cf-builds.garudalinux.org/.*/chaotic-aur/.*$"
|
||||
- server: http://download.zfsonlinux.org
|
||||
path:
|
||||
match: /openzfs/(.*)
|
||||
replace: /$1
|
||||
|
||||
misc:
|
||||
first-chunk-bytes: 31457280 ## 1024*1024*30, all upstreams with 200 response will wait for the first chunks to select a upstream by bandwidth, instead of by latency. defaults to 50M
|
||||
|
Loading…
x
Reference in New Issue
Block a user