(req request.RuntimeSearch)
| 195 | } |
| 196 | |
| 197 | func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.RuntimeDTO, error) { |
| 198 | var ( |
| 199 | opts []repo.DBOption |
| 200 | res []response.RuntimeDTO |
| 201 | ) |
| 202 | if req.Name != "" { |
| 203 | opts = append(opts, repo.WithByLikeName(req.Name)) |
| 204 | } |
| 205 | if req.Status != "" { |
| 206 | if req.Type == constant.TypePhp { |
| 207 | opts = append(opts, runtimeRepo.WithNormalStatus(req.Status)) |
| 208 | } else { |
| 209 | opts = append(opts, runtimeRepo.WithStatus(req.Status)) |
| 210 | } |
| 211 | } |
| 212 | if req.Type != "" { |
| 213 | opts = append(opts, repo.WithByType(req.Type)) |
| 214 | } |
| 215 | total, runtimes, err := runtimeRepo.Page(req.Page, req.PageSize, opts...) |
| 216 | if err != nil { |
| 217 | return 0, nil, err |
| 218 | } |
| 219 | if len(runtimes) == 0 { |
| 220 | return 0, res, nil |
| 221 | } |
| 222 | if err = SyncRuntimesStatus(runtimes); err != nil { |
| 223 | return 0, nil, err |
| 224 | } |
| 225 | for _, runtime := range runtimes { |
| 226 | if runtime.Resource == constant.ResourceLocal { |
| 227 | runtime.Status = constant.StatusNormal |
| 228 | } |
| 229 | runtimeDTO := response.NewRuntimeDTO(runtime) |
| 230 | runtimeDTO.Params = make(map[string]interface{}) |
| 231 | envs, err := gotenv.Unmarshal(runtime.Env) |
| 232 | if err != nil { |
| 233 | return 0, nil, err |
| 234 | } |
| 235 | detail, _ := appDetailRepo.GetFirst(repo.WithByID(runtime.AppDetailID)) |
| 236 | if detail.AppId == 0 { |
| 237 | appID, appDetailID := handleRuntimeDetailID(runtime) |
| 238 | runtimeDTO.AppDetailID = appDetailID |
| 239 | runtimeDTO.AppID = appID |
| 240 | } else { |
| 241 | runtimeDTO.AppID = detail.AppId |
| 242 | } |
| 243 | for k, v := range envs { |
| 244 | runtimeDTO.Params[k] = v |
| 245 | if strings.Contains(k, "CONTAINER_PORT") || strings.Contains(k, "HOST_PORT") { |
| 246 | if strings.Contains(k, "CONTAINER_PORT") { |
| 247 | matches := re.GetRegex(re.TrailingDigitsPattern).FindStringSubmatch(k) |
| 248 | if len(matches) < 2 { |
| 249 | continue |
| 250 | } |
| 251 | containerPort, err := strconv.Atoi(v) |
| 252 | if err != nil { |
| 253 | continue |
| 254 | } |
nothing calls this directly
no test coverage detected