cache-proxy/config.go
guochao 83dfcba4ae
All checks were successful
build container / build-container (push) Successful in 5m45s
run go test / test (push) Successful in 3m15s
move x-accel into local storage configuration
2025-03-03 09:15:37 +08:00

74 lines
1.8 KiB
Go

package cacheproxy
import (
"regexp"
"time"
)
type UpstreamPriorityGroup struct {
Match string `yaml:"match"`
Priority int `yaml:"priority"`
}
type UpstreamMatch struct {
Match string `yaml:"match"`
Replace string `yaml:"replace"`
}
type Upstream struct {
Server string `yaml:"server"`
Match UpstreamMatch `yaml:"match"`
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 == "" {
return orig, true, nil
}
matcher, err := regexp.Compile(upstream.Match.Match)
if err != nil {
return "", false, err
}
return matcher.ReplaceAllString(orig, upstream.Match.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"`
}