(http *gin.Context)
| 251 | } |
| 252 | |
| 253 | func (self Image) GetList(http *gin.Context) { |
| 254 | type ParamsValidate struct { |
| 255 | Tag string `json:"tag" binding:"omitempty"` |
| 256 | Use int `json:"use"` |
| 257 | } |
| 258 | params := ParamsValidate{} |
| 259 | if !self.Validate(http, ¶ms) { |
| 260 | return |
| 261 | } |
| 262 | |
| 263 | var result []image.Summary |
| 264 | imageList, err := docker.Sdk.Client.ImageList(docker.Sdk.Ctx, image.ListOptions{ |
| 265 | All: false, |
| 266 | Manifests: true, |
| 267 | }) |
| 268 | if err != nil { |
| 269 | self.JsonResponseWithError(http, err, 500) |
| 270 | return |
| 271 | } |
| 272 | containerList, _ := docker.Sdk.Client.ContainerList(docker.Sdk.Ctx, container.ListOptions{ |
| 273 | All: true, |
| 274 | }) |
| 275 | |
| 276 | for key, summary := range imageList { |
| 277 | if imageList[key].Containers == -1 { |
| 278 | imageList[key].Containers = 0 |
| 279 | for _, cItem := range containerList { |
| 280 | if cItem.ImageID == summary.ID { |
| 281 | imageList[key].Containers += 1 |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if len(summary.RepoTags) == 0 { |
| 287 | if len(summary.RepoDigests) != 0 { |
| 288 | noneTag := strings.Split(summary.RepoDigests[0], "@") |
| 289 | imageList[key].RepoTags = append(summary.RepoTags, noneTag[0]+":none") |
| 290 | } else { |
| 291 | imageList[key].RepoTags = append(summary.RepoTags, "none") |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | imageDetail, err := docker.Sdk.Client.ImageInspect(docker.Sdk.Ctx, summary.ID) |
| 296 | if err == nil { |
| 297 | if summary.Labels == nil { |
| 298 | imageList[key].Labels = make(map[string]string) |
| 299 | } |
| 300 | imageList[key].Labels["com.dpanel.image.arch"] = imageDetail.Architecture |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | if params.Tag != "" { |
| 305 | result = function.PluckArrayWalk(imageList, func(item image.Summary) (image.Summary, bool) { |
| 306 | for _, tag := range item.RepoTags { |
| 307 | if strings.Contains(tag, params.Tag) { |
| 308 | return item, true |
| 309 | } |
| 310 | } |
nothing calls this directly
no test coverage detected