mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-17 03:04:46 +08:00
fix: 增加buserr实现 修改端口占用提示
This commit is contained in:
parent
8f6b664a53
commit
8bc6545ce2
@ -3,7 +3,6 @@ package service
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -132,11 +131,11 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
|
|||||||
|
|
||||||
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params)
|
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%d port is in used", httpPort)
|
return nil, err
|
||||||
}
|
}
|
||||||
httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", params)
|
httpsPort, err := checkPort("PANEL_APP_PORT_HTTPS", params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%d port is in used", httpsPort)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appDetailId))
|
appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appDetailId))
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -88,7 +89,7 @@ func checkPort(key string, params map[string]interface{}) (int, error) {
|
|||||||
if ok {
|
if ok {
|
||||||
portN := int(math.Ceil(port.(float64)))
|
portN := int(math.Ceil(port.(float64)))
|
||||||
if common.ScanPort(portN) {
|
if common.ScanPort(portN) {
|
||||||
return portN, errors.New("port is in used")
|
return portN, buserr.New(constant.ErrPortInUsed, portN, nil)
|
||||||
} else {
|
} else {
|
||||||
return portN, nil
|
return portN, nil
|
||||||
}
|
}
|
||||||
|
32
backend/buserr/errors.go
Normal file
32
backend/buserr/errors.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package buserr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/i18n"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BusinessError struct {
|
||||||
|
Msg string
|
||||||
|
Detail interface{}
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e BusinessError) Error() string {
|
||||||
|
|
||||||
|
content := i18n.GetErrMsg(e.Msg, map[string]interface{}{"detail": e.Detail})
|
||||||
|
if content == "" {
|
||||||
|
if e.Err != nil {
|
||||||
|
return e.Err.Error()
|
||||||
|
}
|
||||||
|
return errors.New(e.Msg).Error()
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(Key string, detail interface{}, err error) BusinessError {
|
||||||
|
return BusinessError{
|
||||||
|
Msg: Key,
|
||||||
|
Detail: detail,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
}
|
@ -41,3 +41,8 @@ var (
|
|||||||
ErrTypePasswordExpired = "ErrPasswordExpired"
|
ErrTypePasswordExpired = "ErrPasswordExpired"
|
||||||
ErrTypeNotSafety = "ErrNotSafety"
|
ErrTypeNotSafety = "ErrNotSafety"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// app
|
||||||
|
var (
|
||||||
|
ErrPortInUsed = "ErrPortInUsed"
|
||||||
|
)
|
||||||
|
@ -11,15 +11,6 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetMsg(msg string) string {
|
|
||||||
content := ginI18n.MustGetMessage(msg)
|
|
||||||
if content == "" {
|
|
||||||
return msg
|
|
||||||
} else {
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetMsgWithMap(msg string, maps map[string]interface{}) string {
|
func GetMsgWithMap(msg string, maps map[string]interface{}) string {
|
||||||
content := ""
|
content := ""
|
||||||
if maps == nil {
|
if maps == nil {
|
||||||
@ -40,6 +31,21 @@ func GetMsgWithMap(msg string, maps map[string]interface{}) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetErrMsg(msg string, maps map[string]interface{}) string {
|
||||||
|
content := ""
|
||||||
|
if maps == nil {
|
||||||
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: msg,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
content = ginI18n.MustGetMessage(&i18n.LocalizeConfig{
|
||||||
|
MessageID: msg,
|
||||||
|
TemplateData: maps,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
//go:embed lang/*
|
//go:embed lang/*
|
||||||
var fs embed.FS
|
var fs embed.FS
|
||||||
|
|
||||||
|
@ -11,4 +11,8 @@ ErrStructTransform: "Type conversion failure: {{ .detail }}"
|
|||||||
ErrNotLogin: "User is not Login: {{ .detail }}"
|
ErrNotLogin: "User is not Login: {{ .detail }}"
|
||||||
ErrNotSafety: "The login status of the current user is unsafe: {{ .detail }}"
|
ErrNotSafety: "The login status of the current user is unsafe: {{ .detail }}"
|
||||||
ErrPasswordExpired: "The current password has expired: {{ .detail }}"
|
ErrPasswordExpired: "The current password has expired: {{ .detail }}"
|
||||||
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
|
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
|
||||||
|
|
||||||
|
|
||||||
|
#app
|
||||||
|
ErrPortInUsed: "{{ .detail }} 端口已被占用"
|
@ -11,4 +11,8 @@ ErrStructTransform: "类型转换失败: {{ .detail }}"
|
|||||||
ErrNotLogin: "用户未登录: {{ .detail }}"
|
ErrNotLogin: "用户未登录: {{ .detail }}"
|
||||||
ErrNotSafety: "当前用户登录状态不安全: {{ .detail }}"
|
ErrNotSafety: "当前用户登录状态不安全: {{ .detail }}"
|
||||||
ErrPasswordExpired: "当前密码已过期: {{ .detail }}"
|
ErrPasswordExpired: "当前密码已过期: {{ .detail }}"
|
||||||
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
|
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
|
||||||
|
|
||||||
|
|
||||||
|
#app
|
||||||
|
ErrPortInUsed: "{{ .detail }} 已被占用!"
|
||||||
|
@ -115,7 +115,7 @@
|
|||||||
:label="$t('file.updateTime')"
|
:label="$t('file.updateTime')"
|
||||||
prop="modTime"
|
prop="modTime"
|
||||||
:formatter="dateFromat"
|
:formatter="dateFromat"
|
||||||
min-width="100"
|
min-width="150"
|
||||||
show-overflow-tooltip
|
show-overflow-tooltip
|
||||||
></el-table-column>
|
></el-table-column>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user