package clusters import ( "strconv" "strings" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" ) type CreateAction struct { actionutils.ParentAction } func (this *CreateAction) Init() { this.Nav("httpdns", "cluster", "") } func (this *CreateAction) RunGet(params struct{}) { httpdnsutils.AddLeftMenu(this.Parent()) this.Show() } func (this *CreateAction) RunPost(params struct { Name string GatewayDomain string CacheTtl int32 FallbackTimeout int32 InstallDir string IsOn bool Must *actions.Must }) { params.Name = strings.TrimSpace(params.Name) params.GatewayDomain = strings.TrimSpace(params.GatewayDomain) params.InstallDir = strings.TrimSpace(params.InstallDir) if len(params.InstallDir) == 0 { params.InstallDir = "/root/edge-httpdns" } if params.CacheTtl <= 0 { params.CacheTtl = 60 } if params.FallbackTimeout <= 0 { params.FallbackTimeout = 300 } params.Must.Field("name", params.Name).Require("请输入集群名称") params.Must.Field("gatewayDomain", params.GatewayDomain).Require("请输入服务域名") resp, err := this.RPC().HTTPDNSClusterRPC().CreateHTTPDNSCluster(this.AdminContext(), &pb.CreateHTTPDNSClusterRequest{ Name: params.Name, ServiceDomain: params.GatewayDomain, DefaultTTL: params.CacheTtl, FallbackTimeoutMs: params.FallbackTimeout, InstallDir: params.InstallDir, IsOn: params.IsOn, IsDefault: false, AutoRemoteStart: true, AccessLogIsOn: true, TimeZone: "Asia/Shanghai", }) if err != nil { this.ErrorPage(err) return } this.Data["clusterId"] = resp.GetClusterId() // fallback: if frontend JS doesn't intercept form submit, redirect instead of showing raw JSON if len(this.Request.Header.Get("X-Requested-With")) == 0 { this.RedirectURL("/httpdns/clusters/cluster?clusterId=" + strconv.FormatInt(resp.GetClusterId(), 10)) return } this.Success() }