// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. package groups import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils" "github.com/iwind/TeaGo/maps" ) type IndexAction struct { actionutils.ParentAction } func (this *IndexAction) Init() { this.Nav("", "", "group") } func (this *IndexAction) RunGet(params struct{}) { groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.UserContext(), &pb.FindAllEnabledServerGroupsRequest{}) if err != nil { this.ErrorPage(err) return } var groupMaps = []maps.Map{} for _, group := range groupsResp.ServerGroups { countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithServerGroupId(this.UserContext(), &pb.CountAllEnabledServersWithServerGroupIdRequest{ServerGroupId: group.Id}) if err != nil { this.ErrorPage(err) return } countServers := countResp.Count groupMaps = append(groupMaps, maps.Map{ "id": group.Id, "name": group.Name, "countServers": countServers, }) } this.Data["groups"] = groupMaps this.Show() }