cache-proxy/config.go
guochao 835045346d
Some checks failed
build container / build-container (push) Successful in 33m30s
run go test / test (push) Failing after 3s
add header checker
2025-04-01 14:09:43 +08:00

85 lines
2.0 KiB
Go

package cacheproxy
import (
"regexp"
"time"
)
type UpstreamPriorityGroup struct {
Match string `yaml:"match"`
Priority int `yaml:"priority"`
}
type PathTransformation struct {
Match string `yaml:"match"`
Replace string `yaml:"replace"`
}
type HeaderChecker struct {
Name string `yaml:"name"`
Match *string `yaml:"match"`
}
type Checker struct {
StatusCodes []int `yaml:"status-codes"`
Headers []HeaderChecker `yaml:"headers"`
}
type Upstream struct {
Server string `yaml:"server"`
Path PathTransformation `yaml:"path"`
Checkers []Checker `yaml:"checkers"`
AllowedRedirect *string `yaml:"allowed-redirect"`
PriorityGroups []UpstreamPriorityGroup `yaml:"priority-groups"`
}
func (upstream Upstream) GetPath(orig string) (string, bool, error) {
if upstream.Path.Match == "" || upstream.Path.Replace == "" {
return orig, true, nil
}
matcher, err := regexp.Compile(upstream.Path.Match)
if err != nil {
return "", false, err
}
return matcher.ReplaceAllString(orig, upstream.Path.Replace), matcher.MatchString(orig), nil
}
type LocalStorage struct {
Path string `yaml:"path"`
TemporaryFilePattern string `yaml:"temporary-file-pattern"`
Accel Accel `yaml:"accel"`
}
type Accel struct {
EnableByHeader string `yaml:"enable-by-header"`
RespondWithHeaders []string `yaml:"respond-with-headers"`
}
type Storage struct {
Type string `yaml:"type"`
Local *LocalStorage `yaml:"local"`
}
type CachePolicyOnPath struct {
Match string `yaml:"match"`
RefreshAfter string `yaml:"refresh-after"`
}
type Cache struct {
RefreshAfter time.Duration `yaml:"refresh-after"`
Policies []CachePolicyOnPath `yaml:"policies"`
}
type MiscConfig struct {
FirstChunkBytes uint64 `yaml:"first-chunk-bytes"`
ChunkBytes uint64 `yaml:"chunk-bytes"`
}
type Config struct {
Upstreams []Upstream `yaml:"upstream"`
Storage Storage `yaml:"storage"`
Cache Cache `yaml:"cache"`
Misc MiscConfig `yaml:"misc"`
}