update matcher to path matcher

This commit is contained in:
2025-04-01 11:12:34 +08:00
parent e14bcb205b
commit 85968bb5cf
2 changed files with 35 additions and 27 deletions

View File

@ -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 {