// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. //go:build plus package boards import ( teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dashboard/boards/boardutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" ) type HTTPDNSAction struct { actionutils.ParentAction } func (this *HTTPDNSAction) Init() { this.Nav("", "", "httpdns") this.ViewDir("@default") this.View("dashboard/boards/httpdns") } func (this *HTTPDNSAction) RunGet(params struct{}) { if !teaconst.IsPlus { this.RedirectURL("/dashboard") return } err := boardutils.InitBoard(this.Parent()) if err != nil { this.ErrorPage(err) return } this.Data["board"] = maps.Map{ "countApps": 0, "countDomains": 0, "countClusters": 0, "countNodes": 0, "countOfflineNodes": 0, } this.Show() } func (this *HTTPDNSAction) RunPost(params struct{}) { resp, err := this.RPC().HTTPDNSBoardRPC().ComposeHTTPDNSBoard(this.AdminContext(), &pb.ComposeHTTPDNSBoardRequest{}) if err != nil { this.ErrorPage(err) return } this.Data["board"] = maps.Map{ "countApps": resp.CountApps, "countDomains": resp.CountDomains, "countClusters": resp.CountClusters, "countNodes": resp.CountNodes, "countOfflineNodes": resp.CountOfflineNodes, } { var statMaps = []maps.Map{} for _, stat := range resp.HourlyTrafficStats { statMaps = append(statMaps, maps.Map{ "day": stat.Hour[4:6] + "月" + stat.Hour[6:8] + "日", "hour": stat.Hour[8:], "countRequests": stat.CountRequests, "bytes": stat.Bytes, }) } this.Data["hourlyStats"] = statMaps } { var statMaps = []maps.Map{} for _, stat := range resp.DailyTrafficStats { statMaps = append(statMaps, maps.Map{ "day": stat.Day[4:6] + "月" + stat.Day[6:] + "日", "countRequests": stat.CountRequests, "bytes": stat.Bytes, }) } this.Data["dailyStats"] = statMaps } { var statMaps = []maps.Map{} for _, stat := range resp.TopAppStats { statMaps = append(statMaps, maps.Map{ "appId": stat.AppId, "appName": stat.AppName, "countRequests": stat.CountRequests, "bytes": stat.Bytes, }) } this.Data["topAppStats"] = statMaps } { var statMaps = []maps.Map{} for _, stat := range resp.TopDomainStats { statMaps = append(statMaps, maps.Map{ "domainId": stat.DomainId, "domainName": stat.DomainName, "countRequests": stat.CountRequests, "bytes": stat.Bytes, }) } this.Data["topDomainStats"] = statMaps } { var statMaps = []maps.Map{} for _, stat := range resp.TopNodeStats { statMaps = append(statMaps, maps.Map{ "clusterId": stat.ClusterId, "nodeId": stat.NodeId, "nodeName": stat.NodeName, "countRequests": stat.CountRequests, "bytes": stat.Bytes, }) } this.Data["topNodeStats"] = statMaps } this.Success() }