MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / checkPort

Function checkPort

agent/app/service/app_utils.go:58–90  ·  view source on GitHub ↗
(key string, params map[string]interface{})

Source from the content-addressed store, hash-verified

56)
57
58func checkPort(key string, params map[string]interface{}) (int, error) {
59 port, ok := params[key]
60 if ok {
61 portN := 0
62 var err error
63 switch p := port.(type) {
64 case string:
65 portN, err = strconv.Atoi(p)
66 if err != nil {
67 return portN, nil
68 }
69 case float64:
70 portN = int(math.Ceil(p))
71 case int:
72 portN = p
73 }
74
75 oldInstalled, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithPort(portN))
76 if len(oldInstalled) > 0 {
77 var apps []string
78 for _, install := range oldInstalled {
79 apps = append(apps, install.App.Name)
80 }
81 return portN, buserr.WithMap("ErrPortInOtherApp", map[string]interface{}{"port": portN, "apps": apps}, nil)
82 }
83 if common.ScanPort(portN) {
84 return portN, buserr.WithDetail("ErrPortInUsed", portN, nil)
85 } else {
86 return portN, nil
87 }
88 }
89 return 0, nil
90}
91
92func checkPortExist(port int) error {
93 errMap := make(map[string]interface{})

Callers 2

UpdateMethod · 0.70
installWithHooksMethod · 0.70

Calls 2

ListByMethod · 0.65
WithPortMethod · 0.65

Tested by

no test coverage detected