41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package cloud
|
|
|
|
import (
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
|
container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
|
"io"
|
|
"k8s.io/apimachinery/pkg/util/json"
|
|
"net/http"
|
|
)
|
|
|
|
func InstanceCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req container.CreateInstanceParam
|
|
body, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
result.ParamErrorResult(r, w, err)
|
|
return
|
|
}
|
|
|
|
if err = json.Unmarshal(body, &req); err != nil {
|
|
result.ParamErrorResult(r, w, err)
|
|
return
|
|
}
|
|
// 获取token信息
|
|
token := r.Header.Get("Authorization")
|
|
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
|
|
if err != nil {
|
|
result.ParamErrorResult(r, w, err)
|
|
return
|
|
}
|
|
req.UserId = jccUserInfo.Id
|
|
req.Username = jccUserInfo.UserName
|
|
l := cloud.NewInstanceCreateLogic(r.Context(), svcCtx)
|
|
resp, err := l.InstanceCreate(&req)
|
|
result.HttpResult(r, w, resp, err)
|
|
}
|
|
}
|