实现修改缓存配置

This commit is contained in:
刘祥超
2020-09-20 16:27:59 +08:00
parent f238078054
commit ffb06e5b74
15 changed files with 802 additions and 191 deletions

View File

@@ -1,7 +1,7 @@
package serverconfigs
// 代理访问日志配置
type HTTPAccessLogConfig struct {
type HTTPAccessLogRef struct {
IsOn bool `yaml:"isOn" json:"isOn"`
Fields []int `yaml:"fields" json:"fields"` // 记录的字段
@@ -17,8 +17,8 @@ type HTTPAccessLogConfig struct {
}
// 获取新对象
func NewHTTPAccessLogConfig() *HTTPAccessLogConfig {
return &HTTPAccessLogConfig{
func NewHTTPAccessLogRef() *HTTPAccessLogRef {
return &HTTPAccessLogRef{
IsOn: true,
Fields: []int{},
Status1: true,
@@ -30,12 +30,12 @@ func NewHTTPAccessLogConfig() *HTTPAccessLogConfig {
}
// 校验
func (this *HTTPAccessLogConfig) Init() error {
func (this *HTTPAccessLogRef) Init() error {
return nil
}
// 判断是否应该记录
func (this *HTTPAccessLogConfig) Match(status int) bool {
func (this *HTTPAccessLogRef) Match(status int) bool {
s := status / 100
switch s {
case 1:
@@ -64,7 +64,7 @@ func (this *HTTPAccessLogConfig) Match(status int) bool {
}
// 是否包含某个存储策略
func (this *HTTPAccessLogConfig) ContainsStoragePolicy(storagePolicyId int64) bool {
func (this *HTTPAccessLogRef) ContainsStoragePolicy(storagePolicyId int64) bool {
for _, s := range this.StoragePolicies {
if s == storagePolicyId {
return true

View File

@@ -9,7 +9,7 @@ func TestHTTPAccessLogConfig_Match(t *testing.T) {
a := assert.NewAssertion(t)
{
accessLog := NewHTTPAccessLogConfig()
accessLog := NewHTTPAccessLogRef()
a.IsNil(accessLog.Init())
a.IsTrue(accessLog.Match(100))
a.IsTrue(accessLog.Match(200))
@@ -19,7 +19,7 @@ func TestHTTPAccessLogConfig_Match(t *testing.T) {
}
{
accessLog := NewHTTPAccessLogConfig()
accessLog := NewHTTPAccessLogRef()
accessLog.Status1 = false
accessLog.Status2 = false
a.IsNil(accessLog.Init())
@@ -31,7 +31,7 @@ func TestHTTPAccessLogConfig_Match(t *testing.T) {
}
{
accessLog := NewHTTPAccessLogConfig()
accessLog := NewHTTPAccessLogRef()
accessLog.Status3 = false
accessLog.Status4 = false
accessLog.Status5 = false

View File

@@ -7,7 +7,6 @@ import (
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/logs"
"strconv"
"strings"
"time"
)
@@ -16,7 +15,7 @@ var DefaultSkippedResponseCacheControlValues = []string{"private", "no-cache", "
// 缓存策略配置
type HTTPCachePolicy struct {
Id int `yaml:"id" json:"id"`
Id int64 `yaml:"id" json:"id"`
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 TODO
Name string `yaml:"name" json:"name"` // 名称
@@ -114,29 +113,6 @@ func (this *HTTPCachePolicy) LifeDuration() time.Duration {
return this.life
}
// 保存
func (this *HTTPCachePolicy) Save() error {
shared.Locker.Lock()
defer shared.Locker.Unlock()
filename := "cache.policy." + strconv.Itoa(this.Id) + ".conf"
writer, err := files.NewWriter(Tea.ConfigFile(filename))
if err != nil {
return err
}
defer func() {
_ = writer.Close()
}()
_, err = writer.WriteYAML(this)
return err
}
// 删除
func (this *HTTPCachePolicy) Delete() error {
filename := "cache.policy." + strconv.Itoa(this.Id) + ".conf"
return files.NewFile(Tea.ConfigFile(filename)).Delete()
}
// 是否包含某个Cache-Control值
func (this *HTTPCachePolicy) ContainsCacheControl(value string) bool {
return lists.ContainsString(this.uppercaseSkipCacheControlValues, strings.ToUpper(value))

View File

@@ -0,0 +1,6 @@
package serverconfigs
type HTTPCacheRef struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启
CachePolicyId int64 `yaml:"cachePolicyId" json:"cachePolicyId"` // 缓存策略ID
}

View File

@@ -0,0 +1,6 @@
package serverconfigs
type HTTPGzipRef struct {
IsOn bool `yaml:"isOn" json:"isOn"`
GzipId int64 `yaml:"gzipId" json:"gzipId"`
}

View File

@@ -1,9 +1,9 @@
package serverconfigs
type HTTPStatConfig struct {
type HTTPStatRef struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启
}
func (this *HTTPStatConfig) Init() error {
func (this *HTTPStatRef) Init() error {
return nil
}

View File

@@ -3,9 +3,10 @@ package serverconfigs
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
type HTTPWebConfig struct {
Id int64 `yaml:"id" json:"id"` // ID
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Locations []*LocationConfig `yaml:"locations" json:"locations"` // 路径规则 TODO
Id int64 `yaml:"id" json:"id"` // ID
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Locations []*LocationConfig `yaml:"locations" json:"locations"` // 路径规则 TODO
GzipRef *HTTPGzipRef `yaml:"gzipRef" json:"gzipRef"`
Gzip *HTTPGzipConfig `yaml:"gzip" json:"gzip"` // Gzip配置
Charset string `yaml:"charset" json:"charset"` // 字符编码
Shutdown *HTTPShutdownConfig `yaml:"shutdown" json:"shutdown"` // 临时关闭配置
@@ -16,6 +17,7 @@ type HTTPWebConfig struct {
MaxRequestBodySize string `yaml:"maxRequestBodySize" json:"maxRequestBodySize"` // 请求body最大尺寸
RequestHeaders *shared.HTTPHeaderPolicy `yaml:"requestHeaders" json:"requestHeaders"` // 请求Header
ResponseHeaders *shared.HTTPHeaderPolicy `yaml:"responseHeaders" json:"responseHeaders"` // 响应Header`
AccessLog *HTTPAccessLogConfig `yaml:"accessLog" json:"accessLog"` // 访问日志配置
Stat *HTTPStatConfig `yaml:"stat" json:"stat"` // 统计配置
AccessLogRef *HTTPAccessLogRef `yaml:"accessLog" json:"accessLog"` // 访问日志配置
StatRef *HTTPStatRef `yaml:"statRef" json:"statRef"` // 统计配置
CacheRef *HTTPCacheRef `yaml:"cache" json:"cacheRef"`
}