增加检查镜像文件是否存在的接口

Former-commit-id: 31083cc07b2b34ce4bc4f6b69b9b920fb6d3af1b
This commit is contained in:
zhangwei 2023-05-24 17:51:57 +08:00
parent 42275e0d82
commit 27d949fd8e
6 changed files with 85 additions and 2 deletions

View File

@ -192,4 +192,7 @@ service pcm {
@handler imageListHandler
get /image/list () returns (imageListResp)
@handler checkHandler
get /image/check (checkReq) returns (checkResp)
}

View File

@ -118,4 +118,13 @@ type (
name string `json:"name"`
tags []string `json:"tags" copier:"tags"`
}
)
)
type (
checkReq {
fileMd5 string `json:"fileMd5"`
}
checkResp {
exist bool `json:"exist"`
}
)

View File

@ -0,0 +1,28 @@
package image
import (
"net/http"
"PCM/adaptor/PCM-CORE/api/internal/logic/image"
"PCM/adaptor/PCM-CORE/api/internal/svc"
"PCM/adaptor/PCM-CORE/api/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func CheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CheckReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := image.NewCheckLogic(r.Context(), svcCtx)
resp, err := l.Check(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -286,8 +286,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/image/list",
Handler: image.ImageListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/image/check",
Handler: image.CheckHandler(serverCtx),
},
},
rest.WithMaxBytes(624288000),
rest.WithPrefix("/pcm/v1"),
)
}

View File

@ -0,0 +1,31 @@
package image
import (
"context"
"path"
"PCM/adaptor/PCM-CORE/api/internal/svc"
"PCM/adaptor/PCM-CORE/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CheckLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckLogic {
return &CheckLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CheckLogic) Check(req *types.CheckReq) (resp *types.CheckResp, err error) {
// todo: add your logic here and delete this line
path.Join()
return
}

View File

@ -1902,3 +1902,11 @@ type ImageTagsResp struct {
Name string `json:"name"`
Tags []string `json:"tags" copier:"tags"`
}
type CheckReq struct {
FileMd5 string `json:"fileMd5"`
}
type CheckResp struct {
Exist bool `json:"exist"`
}