Files
EdgeAdmin/internal/web/actions/default/servers/components/cache/policy.go

48 lines
1.3 KiB
Go
Raw Normal View History

2020-10-02 17:22:24 +08:00
package cache
2020-10-04 14:27:05 +08:00
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache/cacheutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-10-04 14:27:05 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
2020-10-04 14:27:05 +08:00
)
2020-10-02 17:22:24 +08:00
type PolicyAction struct {
actionutils.ParentAction
}
func (this *PolicyAction) Init() {
2020-10-04 14:27:05 +08:00
this.Nav("", "", "index")
2020-10-02 17:22:24 +08:00
}
2020-10-04 14:27:05 +08:00
func (this *PolicyAction) RunGet(params struct {
CachePolicyId int64
}) {
cachePolicy, err := cacheutils.FindCachePolicy(this.Parent(), params.CachePolicyId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["cachePolicy"] = cachePolicy
2020-10-04 20:38:27 +08:00
this.Data["typeName"] = serverconfigs.FindCachePolicyStorageName(cachePolicy.Type)
2020-10-04 14:27:05 +08:00
// 正在使用此策略的集群
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithHTTPCachePolicyId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithHTTPCachePolicyIdRequest{HttpCachePolicyId: params.CachePolicyId})
if err != nil {
this.ErrorPage(err)
return
}
clusterMaps := []maps.Map{}
for _, cluster := range clustersResp.NodeClusters {
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = clusterMaps
2020-10-02 17:22:24 +08:00
this.Show()
}