(key string, params map[string]interface{})
| 56 | ) |
| 57 | |
| 58 | func 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 | |
| 92 | func checkPortExist(port int) error { |
| 93 | errMap := make(map[string]interface{}) |
no test coverage detected