// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . package trafficstats import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" ) type ServerOptionsAction struct { actionutils.ParentAction } func (this *ServerOptionsAction) RunPost(params struct { UserId int64 }) { if params.UserId == 0 { this.Data["servers"] = []maps.Map{} return } serversResp, err := this.RPC().ServerRPC().FindAllUserServers(this.AdminContext(), &pb.FindAllUserServersRequest{UserId: params.UserId}) if err != nil { this.ErrorPage(err) return } var serverMaps = []maps.Map{ {"id": 0, "name": this.Lang(codes.ServerTrafficStat_AllServers, len(serversResp.Servers))}, } for _, server := range serversResp.Servers { if len(server.FirstServerName) > 0 { server.Name = server.FirstServerName } serverMaps = append(serverMaps, maps.Map{ "id": server.Id, "name": server.Name, }) } this.Data["servers"] = serverMaps this.Success() }