mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-10 04:00:24 +08:00
实现修改缓存配置
This commit is contained in:
34
internal/rpc/services/service_http_cache_policy.go
Normal file
34
internal/rpc/services/service_http_cache_policy.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type HTTPCachePolicyService struct {
|
||||
}
|
||||
|
||||
// 获取所有可用策略
|
||||
func (this *HTTPCachePolicyService) FindAllEnabledHTTPCachePolicies(ctx context.Context, req *pb.FindAllEnabledHTTPCachePoliciesRequest) (*pb.FindAllEnabledHTTPCachePoliciesResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policies, err := models.SharedHTTPCachePolicyDAO.FindAllEnabledCachePolicies()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := []*pb.HTTPCachePolicy{}
|
||||
for _, p := range policies {
|
||||
result = append(result, &pb.HTTPCachePolicy{
|
||||
Id: int64(p.Id),
|
||||
Name: p.Name,
|
||||
IsOn: p.IsOn == 1,
|
||||
})
|
||||
}
|
||||
return &pb.FindAllEnabledHTTPCachePoliciesResponse{CachePolicies: result}, nil
|
||||
}
|
||||
@@ -47,7 +47,6 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
result.Id = int64(web.Id)
|
||||
result.IsOn = web.IsOn == 1
|
||||
result.Root = web.Root
|
||||
result.GzipId = int64(web.GzipId)
|
||||
result.Charset = web.Charset
|
||||
result.RequestHeaderPolicyId = int64(web.RequestHeaderPolicyId)
|
||||
result.ResponseHeaderPolicyId = int64(web.ResponseHeaderPolicyId)
|
||||
@@ -78,7 +77,7 @@ func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.Updat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebGzip(req.WebId, req.GzipId)
|
||||
err = models.SharedHTTPWebDAO.UpdateWebGzip(req.WebId, req.GzipJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -192,3 +191,19 @@ func (this *HTTPWebService) UpdateHTTPStat(ctx context.Context, req *pb.UpdateHT
|
||||
}
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
// 更改缓存配置
|
||||
func (this *HTTPWebService) UpdateHTTPCache(ctx context.Context, req *pb.UpdateHTTPCacheRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebCache(req.WebId, req.CacheJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user