69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package clusters
|
|
|
|
import (
|
|
"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
|
|
IsDefault 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 = "/opt/edge-httpdns"
|
|
}
|
|
if params.CacheTtl <= 0 {
|
|
params.CacheTtl = 30
|
|
}
|
|
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: params.IsDefault,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
this.Data["clusterId"] = resp.GetClusterId()
|
|
this.Success()
|
|
}
|