mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-13 03:40:27 +08:00
优化安装过程中的错误提示
This commit is contained in:
@@ -59,12 +59,20 @@ func (this *ValidateApiAction) RunPost(params struct {
|
||||
this.FailField("newPort", "端口号不能大于65534")
|
||||
}
|
||||
|
||||
conn, err := net.Dial("tcp", "127.0.0.1:"+params.NewPort)
|
||||
if err == nil {
|
||||
_ = conn.Close()
|
||||
this.FailField("newPort", "此端口已经被别的服务占用,请换一个")
|
||||
if net.ParseIP(params.NewHost) == nil {
|
||||
this.FailField("newHost", "请输入正确的节点主机地址")
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", params.NewHost+":"+params.NewPort)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "in use") {
|
||||
this.FailField("newPort", "端口 \""+params.NewPort+"\" 已经被别的服务占用,请关闭正在使用此端口的其他应用程序,或者使用另外一个端口")
|
||||
} else {
|
||||
this.FailField("newHost", "无法正确绑定端口地址,请检查主机地址:"+err.Error())
|
||||
}
|
||||
}
|
||||
_ = listener.Close()
|
||||
|
||||
params.Must.
|
||||
Field("newHost", params.NewHost).
|
||||
Require("请输入节点主机地址")
|
||||
|
||||
@@ -47,6 +47,10 @@ func (this *ValidateDbAction) RunPost(params struct {
|
||||
this.Fail("数据库信息错误:" + err.Error())
|
||||
}
|
||||
|
||||
defer func() {
|
||||
_ = db.Close()
|
||||
}()
|
||||
|
||||
err = db.Raw().Ping()
|
||||
if err != nil {
|
||||
// 是否是数据库不存在
|
||||
@@ -62,10 +66,24 @@ func (this *ValidateDbAction) RunPost(params struct {
|
||||
this.Fail("尝试创建数据库失败:" + err.Error())
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "Error 1044:") {
|
||||
this.Fail("无法连接到数据库,权限检查失败:" + err.Error())
|
||||
}
|
||||
this.Fail("无法连接到数据库,请检查配置:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS `edgeTest` ( `id` int )")
|
||||
if err != nil {
|
||||
this.Fail("当前连接的用户无法创建新表,请检查CREATE权限设置:" + err.Error())
|
||||
}
|
||||
|
||||
_, err = db.Exec("ALTER TABLE `edgeTest` CHANGE `id` `id` int")
|
||||
if err != nil {
|
||||
this.Fail("当前连接的用户无法修改表结构,请检查ALTER权限设置:" + err.Error())
|
||||
}
|
||||
|
||||
// 检查数据库版本
|
||||
one, err := db.FindOne("SELECT VERSION() AS v")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user