mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-28 08:26:36 +08:00
实现修改缓存配置
This commit is contained in:
@@ -63,3 +63,13 @@ func (this *HTTPCachePolicyDAO) FindHTTPCachePolicyName(id int64) (string, error
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 查找所有可用的缓存策略
|
||||
func (this *HTTPCachePolicyDAO) FindAllEnabledCachePolicies() (result []*HTTPCachePolicy, err error) {
|
||||
_, err = this.Query().
|
||||
State(HTTPCachePolicyStateEnabled).
|
||||
DescPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -69,14 +69,22 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
if web == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
config := &serverconfigs.HTTPWebConfig{}
|
||||
config.Id = webId
|
||||
config.IsOn = web.IsOn == 1
|
||||
config.Root = web.Root
|
||||
|
||||
// gzip
|
||||
if web.GzipId > 0 {
|
||||
gzipConfig, err := SharedHTTPGzipDAO.ComposeGzipConfig(int64(web.GzipId))
|
||||
if IsNotNull(web.Gzip) {
|
||||
gzipRef := &serverconfigs.HTTPGzipRef{}
|
||||
err = json.Unmarshal([]byte(web.Gzip), gzipRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.GzipRef = gzipRef
|
||||
|
||||
gzipConfig, err := SharedHTTPGzipDAO.ComposeGzipConfig(gzipRef.GzipId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -138,22 +146,32 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
|
||||
// 访问日志
|
||||
if IsNotNull(web.AccessLog) {
|
||||
accessLogConfig := &serverconfigs.HTTPAccessLogConfig{}
|
||||
accessLogConfig := &serverconfigs.HTTPAccessLogRef{}
|
||||
err = json.Unmarshal([]byte(web.AccessLog), accessLogConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.AccessLog = accessLogConfig
|
||||
config.AccessLogRef = accessLogConfig
|
||||
}
|
||||
|
||||
// 统计配置
|
||||
if IsNotNull(web.Stat) {
|
||||
statConfig := &serverconfigs.HTTPStatConfig{}
|
||||
err = json.Unmarshal([]byte(web.Stat), statConfig)
|
||||
statRef := &serverconfigs.HTTPStatRef{}
|
||||
err = json.Unmarshal([]byte(web.Stat), statRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Stat = statConfig
|
||||
config.StatRef = statRef
|
||||
}
|
||||
|
||||
// 缓存配置
|
||||
if IsNotNull(web.Cache) {
|
||||
cacheRef := &serverconfigs.HTTPCacheRef{}
|
||||
err = json.Unmarshal([]byte(web.Cache), cacheRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.CacheRef = cacheRef
|
||||
}
|
||||
|
||||
// TODO 更多配置
|
||||
@@ -190,13 +208,13 @@ func (this *HTTPWebDAO) UpdateWeb(webId int64, root string) error {
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
func (this *HTTPWebDAO) UpdateWebGzip(webId int64, gzipId int64) error {
|
||||
func (this *HTTPWebDAO) UpdateWebGzip(webId int64, gzipJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.GzipId = gzipId
|
||||
op.Gzip = gzipJSON
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -317,6 +335,22 @@ func (this *HTTPWebDAO) UpdateWebStat(webId int64, statJSON []byte) error {
|
||||
return this.NotifyUpdating(webId)
|
||||
}
|
||||
|
||||
// 更改缓存配置
|
||||
func (this *HTTPWebDAO) UpdateWebCache(webId int64, cacheJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.Cache = JSONBytes(cacheJSON)
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.NotifyUpdating(webId)
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
func (this *HTTPWebDAO) NotifyUpdating(webId int64) error {
|
||||
err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
|
||||
|
||||
@@ -10,20 +10,18 @@ type HTTPWeb struct {
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint32 `field:"createdAt"` // 创建时间
|
||||
Root string `field:"root"` // 资源根目录
|
||||
GzipId uint32 `field:"gzipId"` // Gzip配置
|
||||
Charset string `field:"charset"` // 字符集
|
||||
Shutdown string `field:"shutdown"` // 临时关闭页面配置
|
||||
Pages string `field:"pages"` // 特殊页面
|
||||
FirewallId uint32 `field:"firewallId"` // WAF ID
|
||||
CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID
|
||||
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
|
||||
Indexes string `field:"indexes"` // 首页文件列表
|
||||
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
|
||||
StatPolicyId uint32 `field:"statPolicyId"` // 统计策略ID
|
||||
RequestHeaderPolicyId uint32 `field:"requestHeaderPolicyId"` // Request Header策略ID
|
||||
ResponseHeaderPolicyId uint32 `field:"responseHeaderPolicyId"` // Response Header策略
|
||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||
Stat string `field:"stat"` // 统计配置
|
||||
Gzip string `field:"gzip"` // Gzip配置
|
||||
Cache string `field:"cache"` // 缓存配置
|
||||
}
|
||||
|
||||
type HTTPWebOperator struct {
|
||||
@@ -35,20 +33,18 @@ type HTTPWebOperator struct {
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Root interface{} // 资源根目录
|
||||
GzipId interface{} // Gzip配置
|
||||
Charset interface{} // 字符集
|
||||
Shutdown interface{} // 临时关闭页面配置
|
||||
Pages interface{} // 特殊页面
|
||||
FirewallId interface{} // WAF ID
|
||||
CachePolicyId interface{} // 缓存策略ID
|
||||
RedirectToHttps interface{} // 跳转到HTTPS设置
|
||||
Indexes interface{} // 首页文件列表
|
||||
MaxRequestBodySize interface{} // 最大允许的请求内容尺寸
|
||||
StatPolicyId interface{} // 统计策略ID
|
||||
RequestHeaderPolicyId interface{} // Request Header策略ID
|
||||
ResponseHeaderPolicyId interface{} // Response Header策略
|
||||
AccessLog interface{} // 访问日志配置
|
||||
Stat interface{} // 统计配置
|
||||
Gzip interface{} // Gzip配置
|
||||
Cache interface{} // 缓存配置
|
||||
}
|
||||
|
||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||
|
||||
Reference in New Issue
Block a user