镜像列表接口注释 开发中

Former-commit-id: 0df5d171dc5ae18ee9245d8d519bc9986694ff15
This commit is contained in:
zhangwei 2023-07-10 17:05:34 +08:00
parent a13bf4782c
commit d51c5aed55
1 changed files with 25 additions and 28 deletions

View File

@ -3,10 +3,7 @@ package image
import (
"PCM/adaptor/PCM-CORE/api/internal/svc"
"PCM/adaptor/PCM-CORE/api/internal/types"
"PCM/common/tool"
"context"
"encoding/json"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
)
@ -32,29 +29,29 @@ func NewImageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageLi
func (l *ImageListLogic) ImageList() (resp *types.ImageListResp, err error) {
// 获取镜像列表
url := fmt.Sprintf("%s/repository/%s/v2/_catalog", l.svcCtx.Config.NexusUrl, "pcm")
bytes, err := tool.HttpClient("GET", url, nil, "")
json.Unmarshal(bytes, &resp)
result := types.ImageListResp{}
for _, image := range resp.Repositories {
// 获取镜像的tag列表
url := fmt.Sprintf("%s/repository/%s/v2/%s/tags/list", l.svcCtx.Config.NexusUrl, "pcm", image)
bytes, err := tool.HttpClient("GET", url, nil, "")
if err != nil {
return nil, err
}
tags := ImageTags{}
json.Unmarshal(bytes, &tags)
// 拼接镜像名称
for _, tag := range tags.Tags {
var name string
if tag != "latest" {
name = "hub.jcce.dev:18445/" + image + ":" + tag
} else {
name = "hub.jcce.dev:18445/" + image
}
result.Repositories = append(result.Repositories, name)
}
}
return &result, nil
//url := fmt.Sprintf("%s/repository/%s/v2/_catalog", l.svcCtx.Config.NexusUrl, "pcm")
//bytes, err := tool.HttpClient("GET", url, nil, "")
//json.Unmarshal(bytes, &resp)
//result := types.ImageListResp{}
//for _, image := range resp.Repositories {
// // 获取镜像的tag列表
// url := fmt.Sprintf("registry.cn-hangzhou.aliyuncs.com/jointcloud/pcm:", image)
// bytes, err := tool.HttpClient("GET", url, nil, "")
// if err != nil {
// return nil, err
// }
// tags := ImageTags{}
// json.Unmarshal(bytes, &tags)
// // 拼接镜像名称
// for _, tag := range tags.Tags {
// var name string
// if tag != "latest" {
// name = "hub.jcce.dev:18445/" + image + ":" + tag
// } else {
// name = "hub.jcce.dev:18445/" + image
// }
// result.Repositories = append(result.Repositories, name)
// }
//}
return nil, nil
}